Python常用函数笔记
Shape():
- 参数为一个数,返回空;参数为一个矩阵,返回矩阵size。
np.shape(0) #out ()
np.shape([1, 2]) #out (2L,)
np.shape([[1, 2], [3, 4], [5, 6]]) #out (3L,2L)
- A.shape,返回A的size;
A.shape[0],返回A的纵向(Vertical)的size;
A.shape[1],返回A的水平方向(Horizontal)的size;
A.shape[2],返回A的深度方向(Deep)的size;
A = np.array([[[1, 2, 3],
[4, 5, 6]],
[[-1, -2, -3],
[-4, -5, -6]]])
A.shape[0] #out 2L
A.shape[1] #out 3L
A.shape[2] #out 2L
hstack(),vstack(),dstack():
vstack,合并轴0(Vertical);
hstack,合并轴1(Horizontal);
dstack,合并轴2(Deep);
a = [[1], [2], [3]]
b = [[4], [5], [6]]
np.vstack((a,b)) #out [[1, 4], [2, 5], [3, 6]]
c = [1, 2, 3]
d = [4, 5, 6]
np.hstack((a,b)) #out [1, 2, 3, 4, 5, 6]