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