2021年1月17日星期日

Python numpy 2D array sum over certain indices

There is a 2-d array like this:

img = [    [[1, 2, 3], [4, 5, 6], [7, 8, 9]],    [[2, 2, 2], [3, 2, 3], [6, 7, 6]],    [[9, 8, 1], [9, 8, 3], [9, 8, 5]]  ]  

And i just want to get the mean of certain indices which are like this:

indices = [[0, 0], [0, 1]] # which means image[0][0] and image[0][1]  

There was a similar ask about 1-d array in stackoverflow in this link, but it got a error when i tried to use print(image[indices]). Because i want to make it clear that the element of img are those which indicates by indices, and then get the mean of it.

https://stackoverflow.com/questions/65768227/python-numpy-2d-array-sum-over-certain-indices January 18, 2021 at 10:52AM

没有评论:

发表评论