count#

count(arr=None, val=None, eps=1e-06, **kwargs)[source]#

Count the number of matching elements.

Similar to numpy.count_nonzero(), but allows for slight mismatches (e.g., floats vs. ints). Equivalent to len(sc.findinds()).

Parameters:
  • arr (array) – the array to find values in

  • val (float) – if provided, the value to match

  • eps (float) – the precision for matching (default 1e-6, equivalent to numpy.isclose()’s atol)

  • kwargs (dict) – passed to numpy.isclose()

Examples:

sc.count(rand(10)<0.5) # returns e.g. 4
sc.count([2,3,6,3], 3) # returns 2

New in version 2.0.0.