Count all values in a matrix greater than a value

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

    Here's a variant that uses fancy indexing and has the actual values as an intermediate:

    p31 = numpy.asarray(o31)
    values = p31[p31<200]
    za = len(values)
    

提交回复
热议问题