user391339
user391339

Reputation: 8785

In python what is the most efficient way to get the sum of values in a 2d numpy array?

I am working with opencv mats, which are numpy arrays representing images.

Is there a way to get the sum of all x,y coordinates in a frame that is 1) most efficient 2) most pythonic?

frame[xpos][ypos][0]   #note there are really 3 values for each pixel but i want [0]

Upvotes: 1

Views: 142

Answers (1)

mgilson
mgilson

Reputation: 310049

doesn't:

np.sum(frame[:, :, 0])

return what you want?

Upvotes: 4

Related Questions