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)
| 30 | |
| 31 | |
| 32 | def _tocomplex(arr): |
| 33 | """Convert its input `arr` to a complex array. |
| 34 | |
| 35 | The input is returned as a complex array of the smallest type that will fit |
| 36 | the original data: types like single, byte, short, etc. become csingle, |
| 37 | while others become cdouble. |
| 38 | |
| 39 | A copy of the input is always made. |
| 40 | |
| 41 | Parameters |
| 42 | ---------- |
| 43 | arr : array |
| 44 | |
| 45 | Returns |
| 46 | ------- |
| 47 | array |
| 48 | An array with the same input data as the input but in complex form. |
| 49 | |
| 50 | Examples |
| 51 | -------- |
| 52 | >>> import numpy as np |
| 53 | |
| 54 | First, consider an input of type short: |
| 55 | |
| 56 | >>> a = np.array([1,2,3],np.short) |
| 57 | |
| 58 | >>> ac = np.lib.scimath._tocomplex(a); ac |
| 59 | array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) |
| 60 | |
| 61 | >>> ac.dtype |
| 62 | dtype('complex64') |
| 63 | |
| 64 | If the input is of type double, the output is correspondingly of the |
| 65 | complex double type as well: |
| 66 | |
| 67 | >>> b = np.array([1,2,3],np.double) |
| 68 | |
| 69 | >>> bc = np.lib.scimath._tocomplex(b); bc |
| 70 | array([1.+0.j, 2.+0.j, 3.+0.j]) |
| 71 | |
| 72 | >>> bc.dtype |
| 73 | dtype('complex128') |
| 74 | |
| 75 | Note that even if the input was complex to begin with, a copy is still |
| 76 | made, since the astype() method always copies: |
| 77 | |
| 78 | >>> c = np.array([1,2,3],np.csingle) |
| 79 | |
| 80 | >>> cc = np.lib.scimath._tocomplex(c); cc |
| 81 | array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) |
| 82 | |
| 83 | >>> c *= 2; c |
| 84 | array([2.+0.j, 4.+0.j, 6.+0.j], dtype=complex64) |
| 85 | |
| 86 | >>> cc |
| 87 | array([1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) |
| 88 | """ |
| 89 | if issubclass(arr.dtype.type, (nt.single, nt.byte, nt.short, nt.ubyte, |
no test coverage detected
searching dependent graphs…