python reshape()二维矩阵变一维

代码

import numpy as np

a=np.arange(8).reshape(2,4)
print(a)
print(a.shape)

b=a.reshape(8)
print(b)
print(b.shape)

运行结果

[[0 1 2 3]
[4 5 6 7]]
(2, 4)
[0 1 2 3 4 5 6 7]
(8,)

posted @ 2021-05-18 18:10  sgggr  阅读(2017)  评论(0编辑  收藏  举报