MCPcopy Create free account
hub / github.com/dask/dask / where

Function where

dask/array/routines.py:2156–2172  ·  view source on GitHub ↗
(condition, x=None, y=None)

Source from the content-addressed store, hash-verified

2154
2155@derived_from(np)
2156def where(condition, x=None, y=None):
2157 if (x is None) != (y is None):
2158 raise ValueError("either both or neither of x and y should be given")
2159 if (x is None) and (y is None):
2160 return nonzero(condition)
2161
2162 if np.isscalar(condition):
2163 dtype = result_type(x, y)
2164 x = asarray(x)
2165 y = asarray(y)
2166
2167 shape = broadcast_shapes(x.shape, y.shape)
2168 out = x if condition else y
2169
2170 return broadcast_to(out, shape).astype(dtype)
2171 else:
2172 return elemwise(np.where, condition, x, y)
2173
2174
2175@derived_from(np)

Callers 5

__setitem__Method · 0.90
pushFunction · 0.90
searchsortedFunction · 0.70
trilFunction · 0.70
triuFunction · 0.70

Calls 7

asarrayFunction · 0.90
broadcast_shapesFunction · 0.90
broadcast_toFunction · 0.90
elemwiseFunction · 0.90
result_typeFunction · 0.85
nonzeroFunction · 0.70
astypeMethod · 0.45

Tested by

no test coverage detected