举个简单的例子,要记住,python默认是按行取元素
c = np.array([[1,2,3],[4,5,6]])
输出:
[[1 2 3]
[4 5 6]]
我们看看不同的reshape
print '改成2行3列:'
print c.reshape(2,3)
print '改成3行2列:'
print c.reshape(3,2)
print '我也不知道几行,反正是1列:'
print c.reshape(-1,1)
print '我也不知道几列,反正是1行:'
print c.reshape(1,-1)
print '不分行列,改成1串'
print c.reshape(-1)
输出为:
改成2行3列:
[[1 2 3]
[4 5 6]]
改成3行2列:
[[1 2]
[3 4]
[5 6]]
我也不知道几行,反正是1列:
[[1]
[2]
[3]
[4]
[5]
[6]]
我也不知道几列,反正是1行:
[[1 2 3 4 5 6]]
不分行列,改成1串
[1 2 3 4 5 6]