【笔记】【Python】train.shape中(n,)与(n,1)的差别

python中输入语句时

>>>import numpy as np
>>>a=np.array([1,2,3])
>>>b=np.array([[1],[2],[3]])
>>>c=np.array([[1,2,3]])
>>>a.shape
(3,)
>>>b.shape
(3, 1)
>>>c.shape
(1, 3)

a为一维数据,b和c是二维数据,主要看中括号的个数,来区别是几维数据

train=[[1,2,3,4,5],
       [4,5,6,7,8],
       [8,7,6,5,2],
       [4,3,5,9,1],
       [6,9,2,4,1]]

tmp=[]
for i in range(len(train)-2):                  #对数据进行分割
    tmp.append(train[i:i+2])
tmp=np.array(tmp)

test2=tmp[:,-1][:,0]
print(test2.shape,test2)    #代表一维数组

上一篇:python 图像处理的同态滤波复现


下一篇:Oracle报错问题处理(随笔记录)