#np.reshape函数
x = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 2, 1]])#要是矩阵形式
print('====================')
print(x.reshape(2, 6))
print('====================')
print(x.reshape(1,-1))#1行,列匹配
print('===================')
print(x.reshape(-1,2))#2列,行匹配
结果=======================================
====================
[[1 2 3 4 5 6]
[7 8 9 1 2 1]]
====================
[[1 2 3 4 5 6 7 8 9 1 2 1]]
===================
[[1 2]
[3 4]
[5 6]
[7 8]
[9 1]
[2 1]]
python.np.reshape
最新推荐文章于 2024-06-13 17:27:44 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)