Count all values in a matrix greater than a value

前端 未结 5 1040
一向
一向 2020-12-08 03:57

I have to count all the values in a matrix (2-d array) that are greater than 200.

The code I wrote down for this is:

za=0   
p31 = numpy.asarray(o31)         


        
5条回答
  •  不思量自难忘°
    2020-12-08 04:18

    This is very straightforward with boolean arrays:

    p31 = numpy.asarray(o31)
    za = (p31 < 200).sum() # p31<200 is a boolean array, so `sum` counts the number of True elements
    

提交回复
热议问题