You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

InterX函数Python调用异常:曲线交点计算返回[None,None]求助

Fixing InterX Returning [None, None] for Curve-Line Intersection

Let's break down why your InterX function is returning [None, None] instead of the expected [3.5, 0]:

The Core Issue: Incorrect Line Data Structure

Your line is defined by points (2,3) and (4,-1), but the way you constructed the Line DataFrame mixed up the coordinates.

When you create Line = pd.DataFrame(np.array((X_P,Z_P))), you're stacking X_P and Z_P as rows instead of columns. This means:

  • Line[0] becomes [2, 3] (first element of X_P and first element of Z_P)
  • Line[1] becomes [4, -1] (second element of X_P and second element of Z_P)

This is not the X and Z coordinate array for your line—you're passing a completely different line to InterX!

Corrected Code

Here's the fixed version with proper data structure setup:

import numpy as np
import pandas as pd
from InterX import InterX

# Define the curve points
x_t = np.linspace(0, 10, 10, True)
z_t = np.array((0, 0, 0, 0, 0, 0, 0.055, 0.41, 1.23, 4))

# Define the line points (X and Z coordinates)
X_P = np.array((2,4))
Z_P = np.array((3,-1))

# Option 1: Use the arrays directly (simplest)
P = InterX(X_P, Z_P, x_t, z_t)

# Option 2: If you need DataFrames for other processing:
Line = pd.DataFrame(np.array([X_P, Z_P]).T)  # Transpose to get columns as X/Z
Curve = pd.DataFrame(np.array([x_t, z_t]).T)
P = InterX(Line[0], Line[1], Curve[0], Curve[1])

print(P)  # Should output [3.5, 0]

Why This Works

  • For the line, we now pass the actual X coordinate array [2,4] and Z coordinate array [3,-1] to InterX, which matches the line you intended.
  • The curve's coordinates are correctly structured (you already fixed this with Curve = Curve.T), so Curve[0] is the full x_t array and Curve[1] is z_t.

Additional Checks

If you still run into issues, verify:

  1. That your InterX function expects coordinate arrays in the order (x1, y1, x2, y2) (line first, curve second, or vice versa—double-check the function's documentation).
  2. That the input arrays are 1-dimensional (pandas Series should work, but converting to numpy arrays with .values or .to_numpy() can help avoid edge cases).

内容的提问来源于stack exchange,提问作者hotalora

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 09:28:57