shape描述的是矩阵的形状。
1 一般用法
import numpy as np
a=np.array([1,2,3])
print(a.shape)
# result
3
b=np.array([[1,2,3],[4,5,6],[7,8,9]])
print(b.shape)
# result
(3,3)
c=np.array([[[1,2,3],[4,5,6],[7,8,9]]])
print(c.shape)
# result
(1,3,3) #(H,W,C)
2 特殊用法
import cv2
img = cv2.imread('../DAVIS-2016/JPEGImages/1080p/swing/00005.jpg')
print(img.shape)
print(img.shape[:1]) # 输出从第一项到第一项
print(img.shape[:2]) # 输出从第一项到第二项
print(img.shape[:3]) # 输出从第一项到第三项
print(img.shape[2:]) # 输出从第2+1项到最后一项
print(img.shape[1:]) # 输出从第2项到最后一项
print(img.shape[0:]) # 输出第一项到最后一项
# result
(1080, 1920, 3)
(1080,)
(1080, 1920)
(1080, 1920, 3)
(3,)
(1920, 3)
(1080, 1920, 3)
6560

被折叠的 条评论
为什么被折叠?



