This is a pre-release version (latest). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy latest / 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

: array

An array with the same input data as the input but in complex form.

Examples

import numpy as np
First, consider an input of type short:
a = np.array([1,2,3],np.short)
ac = np.lib.scimath._tocomplex(a); ac
ac.dtype
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
bc.dtype
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
c *= 2; c
cc

Aliases

  • numpy.lib._scimath_impl._tocomplex