Polly
Polly

Reputation: 1097

Python: count the matrix values according to the threshold

Help me, please) I have a numpy array 160x160 What i need is to count an amount of indexes whose value is between value a and b. What i tried: A - my matrix

for i in A:
   for j in A[i]:
      if A[i,j] < 0.1 and A[i,j]> 0:
          m=collections.Counter(don't know what to write here)

Thank you!

Upvotes: 0

Views: 34

Answers (1)

Zero
Zero

Reputation: 76917

Here's an example extension for the comment

Let arr be random array

In [33]: arr = np.random.rand(160,160)

Get the number of elements which are >0 & <0.1

In [34]: ((arr>0) & (arr<0.1)).sum()
Out[34]: 2649

Upvotes: 1

Related Questions