numpy将N-D数组转换为不循环的(N-1)D数组列表



如何将numpy和数组转换为无循环的(n-1)d列表

假设我们有一个数组3d numpy数组

arr3d = np.random.randint(1, 100, size=7 * 3 * 6).reshape((7, 3, 6))

with loop(慢解):

arr_what_i_want= []
for i in range(7):
arr2d = arr3d[i]
arr_what_i_want.append([arr2d])
pass

如何获取"arr_what_i_want">没有循环吗?

列出第一个维度:

arr_what_i_want = [*arr3d]

arr_what_i_want = list(arr3d)

让我猜一下:

arr3d = np.random.randint(1, 100, size=7 * 3 * 6).reshape((7, 3, 6))
arr2d = arr3d.reshape(arr3d.shape[0], (arr3d.shape[1]*arr3d.shape[2]))
print(arr2d)

输出:
[[68年29 30 22 13 93 93 91 8 82 34 48 41 83 72 75 25 38]
[12 43 4 76 21 84 26日26日10 76 42 49 66 40 22日31日13]
[28 64 84 83 33 97 11 95 37 61 42 18 31 3 67 86]
[94 73 2 26日23 94 69 49 40 39 60 79 84 39 57 94 76 16]
[83 5 65 23 42 49 48 84 82 55 69 19 18 51 4 49 81]
[51 48 56 73 63 88 92年57 12 31日25 98 46 67 38 73 60]
[42 8 47 13 76 40 71 54 99 58 47 93 2 56 38 9 73 36]]

最新更新