Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arrays 如何使用列表元素的非整数步长创建meshgrid?_Arrays_Python 3.x_List Comprehension_Numpy Slicing - Fatal编程技术网

Arrays 如何使用列表元素的非整数步长创建meshgrid?

Arrays 如何使用列表元素的非整数步长创建meshgrid?,arrays,python-3.x,list-comprehension,numpy-slicing,Arrays,Python 3.x,List Comprehension,Numpy Slicing,我有两个独立生成的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]

我有两个独立生成的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]
其中
电势(V1)
现在是
V1
对应于网格
[x,y]
。然而,我正在做一项作业,要求我调查步长如何影响我的问题。因此,如果我的非整数步长是从
0
a
,即
[0,0.5,1,…,a]
,那么我就不能像上面那样做了,因为索引现在是非整数。提出错误

IndexError: arrays used as indices must be of integer (or boolean) type
我如何解决这个问题,使我不依赖元素本身的值作为元素的索引,这样,如果列表
X
0
a
之间存在
0.25
的步长,比如说

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]
?