Count all values in a matrix greater than a value

前端 未结 5 1038
一向
一向 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:09

    To count the number of values larger than x in any numpy array you can use:

    n = len(matrix[matrix > x])
    

    The boolean indexing returns an array that contains only the elements where the condition (matrix > x) is met. Then len() counts these values.

提交回复
热议问题