reshape(1,-1)与reshape(-1,1)的理解

reshape(-1,1)中的-1代表无意义
reshape(-1,1)代表将二维数组重整为一个一列的二维数组
reshape(1,-1)代表将二维数组重整为一个一行的二维数组
reshape(-1,n)代表将二维数组重整为n列的二维数组
reshape(n,-1)代表将二维数组重整为n行的二维数组
代码:

import numpy as np
x=np.array([[1,2,3],[2,3,5],[11,15,17],[58,2,87],[5,8,2],[1,4,3]])
a=x.reshape(-1,1)
print(a)

输出:

[[ 1]
 [ 2]
 [ 3]
 [ 2]
 [ 3]
 [ 5]
 [11]
 [15]
 [17]
 [58]
 [ 2]
 [87]
 [ 5]
 [ 8]
 [ 2]
 [ 1]
 [ 4]
 [ 3]]

代码:

import numpy as np
x=np.array([[1,2,3],[2,3,5],[11,15,17],[58,2,87],[5,8,2],[1,4,3]])
a=x.reshape(1,-1)
print(a)

输出:

[[ 1  2  3  2  3  5 11 15 17 58  2 87  5  8  2  1  4  3]]
1
代码:

import numpy as np
x=np.array([[1,2,3],[2,3,5],[11,15,17],[58,2,87],[5,8,2],[1,4,3]])
a=x.reshape(3,-1)
print(a)

输出:

[[ 1  2  3  2  3  5]
 [11 15 17 58  2 87]
 

猜你喜欢

转载自blog.csdn.net/zhaomengsen/article/details/131063911