我正在以下列方式遍历ndarray(由calcOpticalFlowFarneback
- openCV返回)
for ((y, x, v), val) in np.ndenumerate(my_ndarray):
print ("At row " , x , " and column " , y , " we have at index ", v, " the component ", val, ")")
获取输出
('At row ', 0L, ' and column ', 0L, ' we have at index ', 0L, ' the component ', -1.539571e-05, ')')
('At row ', 0L, ' and column ', 0L, ' we have at index ', 1L, ' the component ', 0.21003947, ')')
因为这是一对矩阵(矩阵中的每个单元都有一个向量的两个分量),有没有办法可以在同一个循环中访问这些值
for ((y, x), (val1, val2)) in np.ndenumerate(my_ndarray):
^^^^^^^^^^^^^^^^^^^^^^ not working
即。通过完全跳过0-1索引?
不幸的是,我上面尝试的代码无效