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

Function where

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

Source from the content-addressed store, hash-verified

2106
2107@derived_from(np)
2108def where(condition, x=None, y=None):
2109 if (x is None) != (y is None):
2110 raise ValueError("either both or neither of x and y should be given")
2111 if (x is None) and (y is None):
2112 return nonzero(condition)
2113
2114 if np.isscalar(condition):
2115 dtype = result_type(x, y)
2116 x = asarray(x)
2117 y = asarray(y)
2118
2119 shape = broadcast_shapes(x.shape, y.shape)
2120 out = x if condition else y
2121
2122 return broadcast_to(out, shape).astype(dtype)
2123 else:
2124 return elemwise(np.where, condition, x, y)
2125
2126
2127@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