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 -------- >>> import numpy as np >>> np.lib.scimath._
(x)
| 94 | |
| 95 | |
| 96 | def _fix_real_lt_zero(x): |
| 97 | """Convert `x` to complex if it has real, negative components. |
| 98 | |
| 99 | Otherwise, output is just the array version of the input (via asarray). |
| 100 | |
| 101 | Parameters |
| 102 | ---------- |
| 103 | x : array_like |
| 104 | |
| 105 | Returns |
| 106 | ------- |
| 107 | array |
| 108 | |
| 109 | Examples |
| 110 | -------- |
| 111 | >>> import numpy as np |
| 112 | >>> np.lib.scimath._fix_real_lt_zero([1,2]) |
| 113 | array([1, 2]) |
| 114 | |
| 115 | >>> np.lib.scimath._fix_real_lt_zero([-1,2]) |
| 116 | array([-1.+0.j, 2.+0.j]) |
| 117 | |
| 118 | """ |
| 119 | x = asarray(x) |
| 120 | if any(isreal(x) & (x < 0)): |
| 121 | x = _tocomplex(x) |
| 122 | return x |
| 123 | |
| 124 | |
| 125 | def _fix_int_lt_zero(x): |