0

我有一个形状的numpy数组arr.shape: (416809, )

其中有:

arr[0].shape:
(300,)

我希望重塑为(416809, 300)

我正在搜索文档,但找不到解决方案。

任何帮助将不胜感激!

谢谢!

4

1 回答 1

1

要转换 a 的形状NumPy array ndarray,请使用 的reshape()方法ndarraynumpy.reshape()函数。

这是一个示例供您参考

import numpy as np

a = np.arange(24)

print(a)
# [ 0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23]

print(a.shape)
# (24,)

a_4_6 = a.reshape([4, 6])

print(a_4_6)
# [[ 0  1  2  3  4  5]
#  [ 6  7  8  9 10 11]
#  [12 13 14 15 16 17]
#  [18 19 20 21 22 23]]
于 2020-08-02T17:03:17.987 回答