Convert `x` to complex if it has real, negative components. Otherwise, output is just the array version of the input (via asarray). Parameters ---------- x : array_like Returns ------- array Examples -------- >>> np.lib.scimath._fix_real_lt_zero([1,2])
(x)
| 110 | |
| 111 | |
| 112 | def _fix_real_lt_zero(x): |
| 113 | """Convert `x` to complex if it has real, negative components. |
| 114 | |
| 115 | Otherwise, output is just the array version of the input (via asarray). |
| 116 | |
| 117 | Parameters |
| 118 | ---------- |
| 119 | x : array_like |
| 120 | |
| 121 | Returns |
| 122 | ------- |
| 123 | array |
| 124 | |
| 125 | Examples |
| 126 | -------- |
| 127 | >>> np.lib.scimath._fix_real_lt_zero([1,2]) |
| 128 | array([1, 2]) |
| 129 | |
| 130 | >>> np.lib.scimath._fix_real_lt_zero([-1,2]) |
| 131 | array([-1.+0.j, 2.+0.j]) |
| 132 | |
| 133 | """ |
| 134 | x = asarray(x) |
| 135 | if any(isreal(x) & (x < 0)): |
| 136 | x = _tocomplex(x) |
| 137 | return x |
| 138 | |
| 139 | |
| 140 | def _fix_int_lt_zero(x): |