【发布时间】:2021-09-25 23:10:17
【问题描述】:
我知道这可能是一个愚蠢的问题(请告诉我)。 当我打印出一个形状为 (2, 493, 452) 的数组时,应该有 2 行吧?为什么下面看起来像多行(例如第一行是[ 0 0 0...0 0 0])然后对于第二个输出(2,222836),这意味着有2行和222836列?
(2, 493, 452)
[[[ 0 0 0 ... 0 0 0]
[ 1 1 1 ... 1 1 1]
[ 2 2 2 ... 2 2 2]
...
[490 490 490 ... 490 490 490]
[491 491 491 ... 491 491 491]
[492 492 492 ... 492 492 492]]
[[ 0 1 2 ... 449 450 451]
[ 0 1 2 ... 449 450 451]
[ 0 1 2 ... 449 450 451]
...
[ 0 1 2 ... 449 450 451]
[ 0 1 2 ... 449 450 451]
[ 0 1 2 ... 449 450 451]]]
(2, 222836)
[[ 0 0 0 ... 492 492 492]
[ 0 1 2 ... 449 450 451]]
这是我的代码:
original_image=cv2.imread("mickey mouse.jpg")
img=cv2.cvtColor(original_image,cv2.COLOR_BGR2RGB)
vectorized=img.reshape((-1,3))
#print(vectorized.shape)
#print(vectorized)
ind=np.indices((m,n))
print(ind.shape)
print(ind)
ind.resize((2,m*n))
print(ind.shape)
print(ind)
【问题讨论】:
-
它不是矩阵,它是张量......所以有三个维度......宽度,高度和深度
-
当你检查
[ ]时,它是有道理的。 -
我更喜欢将第一个维度称为“平面”或“块”,并且只对最后两个维度使用行/列。但是像这样的名字只是为了我们人类的方便。它们不是
numpy代码或文档的一部分。