numpy的reshape()方法用于将数据从新组织,由于保存记录方便查看
import numpy as np
a=np.array([[1,2,3],[4,5,6],[7,8,9],[10,11,12]])
a
#运行结果
array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 11, 12]])
a.reshape(2,6)
#运行结果
>>>array([[ 1, 2, 3, 4, 5, 6],
[ 7, 8, 9, 10, 11, 12]])
a.reshape(-1,1)
#运行结果,-1代表未指定行数
>>>array([[ 1],
[ 2],
[ 3],
[ 4],
[ 5],
[ 6],
[ 7],
[ 8],
[ 9],
[10],
[11],
[12]])
a.reshape(1,-1)
#运行结果,-1代表未指定列数
array([[ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]])