where¶

sparse.where(condition, x=None, y=None)[source]

Select values from either x or y depending on condition. If x and y are not given, returns indices where condition is nonzero.

Performs the equivalent of numpy.where.

Parameters
• condition (SparseArray) – The condition based on which to select values from either x or y.

• x (SparseArray, optional) – The array to select values from if condition is nonzero.

• y (SparseArray, optional) – The array to select values from if condition is zero.

Returns

The output array with selected values if x and y are given; else where the array is nonzero.

Return type

COO

Raises

ValueError – If the operation would produce a dense result; or exactly one of x and y are given.

numpy.where()