bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / lib / _scimath_impl / _tocomplex
function
numpy.lib._scimath_impl:_tocomplex
source: build-install/usr/lib/python3.14/site-packages/numpy/lib/_scimath_impl.py:32
Signature
def _tocomplex(arr)Summary
Convert its input arr to a complex array.
Extended Summary
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: array
Returns
: arrayAn array with the same input data as the input but in complex form.
Examples
import numpy as np
✓a = np.array([1,2,3],np.short)
✓ac = np.lib.scimath._tocomplex(a); ac
⚠Traceback (most recent call last):
File "<doctest numpy.lib._scimath_impl:_tocomplex[0]>", line 1, in <module>
ac = np.lib.scimath._tocomplex(a); ac
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'numpy.lib.scimath' has no attribute '_tocomplex'
ac.dtype
⚠Traceback (most recent call last):
File "<doctest numpy.lib._scimath_impl:_tocomplex[0]>", line 1, in <module>
ac.dtype
^^
NameError: name 'ac' is not defined. Did you mean: 'a'?
If the input is of type double, the output is correspondingly of the
complex double type as well:
b = np.array([1,2,3],np.double)
✓bc = np.lib.scimath._tocomplex(b); bc
⚠Traceback (most recent call last):
File "<doctest numpy.lib._scimath_impl:_tocomplex[0]>", line 1, in <module>
bc = np.lib.scimath._tocomplex(b); bc
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'numpy.lib.scimath' has no attribute '_tocomplex'
bc.dtype
⚠Traceback (most recent call last):
File "<doctest numpy.lib._scimath_impl:_tocomplex[0]>", line 1, in <module>
bc.dtype
^^
NameError: name 'bc' is not defined. Did you mean: 'b'?
Note that even if the input was complex to begin with, a copy is still
made, since the astype() method always copies:
c = np.array([1,2,3],np.csingle)
✓cc = np.lib.scimath._tocomplex(c); cc
⚠Traceback (most recent call last):
File "<doctest numpy.lib._scimath_impl:_tocomplex[0]>", line 1, in <module>
cc = np.lib.scimath._tocomplex(c); cc
^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module 'numpy.lib.scimath' has no attribute '_tocomplex'
c *= 2; c
✗array([2.+0.j, 4.+0.j, 6.+0.j], dtype=complex64)
cc
⚠Traceback (most recent call last):
File "<doctest numpy.lib._scimath_impl:_tocomplex[0]>", line 1, in <module>
cc
NameError: name 'cc' is not defined. Did you mean: 'c'?
Aliases
numpy.lib._scimath_impl._tocomplex