(condition, x=None, y=None)
| 2154 | |
| 2155 | @derived_from(np) |
| 2156 | def 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) |
no test coverage detected