python - 多维 Numpy 数组的 Numpy.reshape 给出相同的大小但不同的数字顺序
问题描述
我想将 shape 数组转换(a, b, c, d)
为 shape (b*c*d, a)
。
问题是 Array A 和 B 的输出不同:
x = np.array([np.arange(1,37)]) #1D array of 1 to 36.
a = 3
b = 2
c = 2
d = 3
Array = np.reshape(x, (a, b, c, d)) #shape (3, 2, 2, 3)
A = poop.reshape(a, b*c*d).T
B = poop.reshape(b*c*d, a)
print("Array shape:" + str(Array.shape))
print(Array)
print("#####")
print("Array A:")
print(A)
print("#####")
print("Array B:")
print(B)
我认为 Numpy 的重塑将(row, column)
作为输入,因此反转然后转置会导致相同的结果(column, row).T
。
更改“Order”参数似乎不会使数组 B 与数组 A 匹配。
谢谢你。
输出是:
Array shape:(3, 2, 2, 3)
[[[[ 1 2 3]
[ 4 5 6]]
[[ 7 8 9]
[10 11 12]]]
[[[13 14 15]
[16 17 18]]
[[19 20 21]
[22 23 24]]]
[[[25 26 27]
[28 29 30]]
[[31 32 33]
[34 35 36]]]]
#####
Array A:
[[ 1 13 25]
[ 2 14 26]
[ 3 15 27]
[ 4 16 28]
[ 5 17 29]
[ 6 18 30]
[ 7 19 31]
[ 8 20 32]
[ 9 21 33]
[10 22 34]
[11 23 35]
[12 24 36]]
#####
Array B:
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]
[13 14 15]
[16 17 18]
[19 20 21]
[22 23 24]
[25 26 27]
[28 29 30]
[31 32 33]
[34 35 36]]
解决方案
推荐阅读
- node.js - 无法在 Amazon Linux 上启动 mongoDB
- javascript - 忽略的属性在 HTML 5
- wifi - 尝试多个 AP 和密码,直到使用 micropython 连接到 ESP32
- avro - Avro 嵌套数组异常
- r - 使用实验室时 x 标签的问题(ggplot)
- python - TypeError: __init__() 得到了一个意外的关键字参数“n_iter”。这是我安装 scikit-learn 的方式有问题吗?
- excel - 在列 A 上分组时,B 列中值的 Excel 条件格式
- css - 将 padding-left css 属性添加到清晰度标签标签
- c - 在 C 中的数组中找到 N 个最大整数的最有效(最快)方法是什么?
- flutter - 我更新了我的颤振版本破坏颤振应用程序时出错