python - reshape numpy ndarray

标签 python numpy multidimensional-array

我有一个 numpy ndarray 的 3D 坐标,格式如下。

array([[  0.,   0.,  60.],
       [  0.,  40.,  60.],
       [  0.,  40.,   0.],
       ..., 
       [  6.,   0.,   2.],
       [  4.,   0.,   2.],
       [  2.,   0.,   2.]])

我正在尝试 reshape 它,以便获得 2D 坐标网格,而不是 1D 坐标向量。

原始数组的长度为 1302,这应该允许我将其 reshape 为 21x62 的排列。

我尝试了 coords_reshape = np.ndarray.reshape(coords, (21,62)) 但这抛出了错误,

ValueError: total size of new array must be unchanged

那么我在这里缺少什么?

最佳答案

coords_reshaped = coords.reshape((21, 62, 3))

关于python - reshape numpy ndarray,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38248677/

相关文章:

python - pandas - 根据列值将每行复制 'n' 次

Python3奇怪的列表反转

python - 如何用 pandas 替换一定时间范围内的值及其平均值?

c - 关于在 C 中使用指针定义二维数组

javascript - 在数组javascript中找到最小的数字

python - 如何在 python 中将平面列表转换为二维数组?

Python 用逗号连接只打印键,而不是带有值的键

python - 如何修复 Django 迁移的顺序?

python - Sympy:如何计算矩阵相对于向量场的李导数

python - 在 Python 中读取 .grd 文件