dpctl.tensor.count_nonzero

dpctl.tensor.count_nonzero(x, /, *, axis=None, keepdims=False, out=None)[source]

Counts the number of elements in the input array x which are non-zero.

Parameters:
  • x (usm_ndarray) – input array.

  • axis (Optional[int, Tuple[int, ...]]) – axis or axes along which to count. If a tuple of unique integers, the number of non-zero values are computed over multiple axes. If None, the number of non-zero values is computed over the entire array. Default: None.

  • keepdims (Optional[bool]) – if True, the reduced axes (dimensions) are included in the result as singleton dimensions, so that the returned array remains compatible with the input arrays according to Array Broadcasting rules. Otherwise, if False, the reduced axes are not included in the returned array. Default: False.

  • out (Optional[usm_ndarray]) – the array into which the result is written. The data type of out must match the expected shape and data type. If None then a new array is returned. Default: None.

Returns:

an array containing the count of non-zero values. If the sum was computed over the entire array, a zero-dimensional array is returned. The returned array will have the default array index data type.

Return type:

usm_ndarray