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.ndim) #输出为 1 b = a.reshape(2,4,3) print(b) #输出为 [[[ 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(b.ndim) #输出为 3 print(b.shape) #输出为 (2, 4, 3)
‘‘‘ 输出为 [[1 2 3] [4 5 6]] (2, 3) [[1 2] [3 4] [5 6]] ‘‘‘ import numpy as np a = np.array([[1,2,3],[4,5,6]]) print(a) print(a.shape) #调整数组大小 a = np.array([[1,2,3],[4,5,6]]) a.shape=(1,6) #输出为 [[1 2 3 4 5 6]] print(a) # reshape 调整数组大小 b = a.reshape(3,2) print(b) #输出为 [[1 2] # [3 4] # [5 6]]
原文:https://www.cnblogs.com/lanzhijie/p/12348608.html