Convert its input `arr` to a complex array. The input is returned as a complex array of the smallest type that will fit the original data: types like single, byte, short, etc. become csingle, while others become cdouble. A copy of the input is always made. Parameters -----
(arr)
| 47 | |
| 48 | |
| 49 | def _tocomplex(arr): |
| 50 | """Convert its input `arr` to a complex array. |
| 51 | |
| 52 | The input is returned as a complex array of the smallest type that will fit |
| 53 | the original data: types like single, byte, short, etc. become csingle, |
| 54 | while others become cdouble. |
| 55 | |
| 56 | A copy of the input is always made. |
| 57 | |
| 58 | Parameters |
| 59 | ---------- |
| 60 | arr : array |
| 61 | |
| 62 | Returns |
| 63 | ------- |
| 64 | array |
| 65 | An array with the same input data as the input but in complex form. |
| 66 | |
| 67 | Examples |
| 68 | -------- |
| 69 | |
| 70 | First, consider an input of type short: |
| 71 | |
| 72 | >>> a = np.array([1,2,3],np.short) |
| 73 | |
| 74 | >>> ac = np.lib.scimath._tocomplex(a); ac |
| 75 | array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) |
| 76 | |
| 77 | >>> ac.dtype |
| 78 | dtype('complex64') |
| 79 | |
| 80 | If the input is of type double, the output is correspondingly of the |
| 81 | complex double type as well: |
| 82 | |
| 83 | >>> b = np.array([1,2,3],np.double) |
| 84 | |
| 85 | >>> bc = np.lib.scimath._tocomplex(b); bc |
| 86 | array([1.+0.j, 2.+0.j, 3.+0.j]) |
| 87 | |
| 88 | >>> bc.dtype |
| 89 | dtype('complex128') |
| 90 | |
| 91 | Note that even if the input was complex to begin with, a copy is still |
| 92 | made, since the astype() method always copies: |
| 93 | |
| 94 | >>> c = np.array([1,2,3],np.csingle) |
| 95 | |
| 96 | >>> cc = np.lib.scimath._tocomplex(c); cc |
| 97 | array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) |
| 98 | |
| 99 | >>> c *= 2; c |
| 100 | array([2.+0.j, 4.+0.j, 6.+0.j], dtype=complex64) |
| 101 | |
| 102 | >>> cc |
| 103 | array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) |
| 104 | """ |
| 105 | if issubclass(arr.dtype.type, (nt.single, nt.byte, nt.short, nt.ubyte, |
| 106 | nt.ushort, nt.csingle)): |
no test coverage detected