NPB
NPB

Reputation: 464

python numpy/scipy find count or frequency of a relative variable in multi-dimensional array

I have a three dimensional array, say dat.shape = (100,128,256). I'm trying to count the number of periods that have values greater than 10.0 across the first axis. For example, for dat[:,0,0], how many times does a value greater than 10.0 occur? Then, dat[:,0,1] to dat[:,n,m]. My end matrix would have a shape of (128,156).

Is there a way to do this calculation in numpy or scipy without looping across the 1st and 2nd dimension?

Thank you very much!

Upvotes: 2

Views: 754

Answers (1)

HYRY
HYRY

Reputation: 97301

import numpy as np
a = np.random.randint(0, 100, (100,128,256))
np.sum(a > 10, axis=0)

Upvotes: 3

Related Questions