小编kil*_*ulu的帖子

为什么网格网格对输出尺寸的排序与输入提供的顺序不同?

我试图了解网格网格如何索引输出相对于输入的维度。我注意到它总是会转置前两个维度。例如,当提供长度为 7 的 x 和长度为 6 的 y 时,它将返回输出数组作为 6x7 数组,而不是 7x6 数组。

这显然是设计使然,所以我试图理解原因/逻辑,以便我可以按预期使用它。有人可以阐明这一点吗?谢谢!

import numpy as np

#specify input dimensions of different lengths to aid in identifying which output index a dimension belongs to
x = np.linspace(0,60,7)
y = np.linspace(0,50,6)
z = np.linspace(0,40,5)
i = np.linspace(0,30,4)
j = np.linspace(0,20,3)

#2D mesh grid, output dimensions transposed from input
xx, yy = np.meshgrid(x,y)
print(xx.shape)
print(yy.shape)

#3D mesh grid, first two output dimensions transposed from input
xx, yy, zz = np.meshgrid(x,y,z)
print(xx.shape) …
Run Code Online (Sandbox Code Playgroud)

python numpy

5
推荐指数
2
解决办法
2996
查看次数

标签 统计

numpy ×1

python ×1