1

我有 2 个独立生成的 x 和 y 坐标列表,a/h点数介于0和之间a

x = np.linspace(0, a, a/h)
y = np.linspace(0, d, d/h)

a/h是这样的,以整数为单位0增加,即。这很好,因为列表中的元素数量可以用作索引。因此,我通常可以创建一个网格网格,以便第三个列表可以与之关联。a[0,1,2,..,a]V1

X, Y = plt.meshgrid(x, y)
def potential(V1):
    return V1[X, Y]

wherepotential(V1)现在V1对应于 meshgrid [x, y]。但是,我正在做一项任务,我需要调查步长如何影响我的问题。结果,如果我有一个非整数的步长,0a现在[0, 0.5, 1,...,a]我不能做我上面所做的,因为索引现在是非整数。提出错误

IndexError: arrays used as indices must be of integer (or boolean) type

我该如何解决这个问题,以便我不依赖元素本身的值作为元素的索引,这样如果列表0.25之间存在步长0,例如aX

X = [0, 0.25, 0.75. 1.0] or x = np.linspace(0,1,4)

这样我就可以拥有

x[0] = 0 corresponds to V[0]
x[1] = 0.25 corresponds to V[1]
x[2] = 0.75 corresponds to V[2]
x[3] = 1 corresponds to V[3]

?

4

0 回答 0