简体   繁体   English

如何在NumPy中更改数组数组中的轴的值?

[英]How to change values for axis in array of arrays (of arrays of arrays) in NumPy?

I have a 4-level 4-dimensional array contours (result of cv2.findContours ) at the end of which I have pairs of coordinates. 我有一个4级 4维数组contourscv2.findContours结果),在其末尾有一对坐标。 It looks like this: 看起来像这样:

print(contours[0][0])
→ [[ 676 4145]]
print(contours[0][0][0])
→ [ 676 4145]
print(contours[0][0][0][1])
→ 4145

I want to edit the axis element 1 of each of the last-level arrays so that the value is bigger by 10. I am aware of the documentation , but I don't know how to apply it so deep without flattening. 我想编辑每个最后一级数组的元素1,以使该值大10。我知道文档 ,但是我不知道如何深化而不展平。 How to do that? 怎么做?

这些中的任何一个都可以工作:

  • contours[:,:,:,1] += 10
  • contours[...,1] += 10
  • contours += [0, 10]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM