sidpy.hdf.dtype_utils.flatten_complex_to_real¶
- sidpy.hdf.dtype_utils.flatten_complex_to_real(dataset, lazy=False)[source]¶
Stacks the real values followed by the imaginary values in the last dimension of the given N dimensional matrix. Thus a complex matrix of shape (2, 3, 5) will turn into a matrix of shape (2, 3, 10)
- Parameters:
dataset (array-like or
numpy.ndarray
, orh5py.Dataset
, ordask.array.core.Array
) – Dataset of complex data typelazy (bool, optional. Default = False) – If set to True, will use lazy Dask arrays instead of in-memory numpy arrays
- Returns:
retval – real valued dataset
- Return type:
Examples
>>> import numpy as np >>> import sidpy >>> length = 3 >>> complex_array = np.random.randint(-5, high=5, size=length) + 1j * np.random.randint(-5, high=5, size=length) >>> print('Complex value: {} has shape: {}'.format(complex_array, complex_array.shape)) Complex value: [2.-2.j 0.-3.j 0.-4.j] has shape: (3,)
>>> stacked_real_array = sidpy.dtype_utils.flatten_complex_to_real(complex_array) >>> print('Stacked real value: {} has shape: ' >>> '{}'.format(stacked_real_array, stacked_real_array.shape)) Stacked real value: [ 2. 0. 0. -2. -3. -4.] has shape: (6,)