sidpy.hdf.dtype_utils.stack_real_to_compound

sidpy.hdf.dtype_utils.stack_real_to_compound(ds_real, compound_type, lazy=False)[source]

Converts a real-valued dataset to a compound dataset (along the last axis) of the provided compound d-type

Parameters:
  • ds_real (numpy.ndarray, dask.array.core.Array, or h5py.Dataset) – n dimensional real-valued numpy array or HDF5 dataset where data arranged as [instance, features]

  • compound_type (numpy.dtype) – Target complex data-type

  • lazy (bool, optional. Default = False) – If set to True, will use lazy Dask arrays instead of in-memory numpy arrays

Returns:

ds_compound – N-dimensional complex-valued array arranged as [sample, features]

Return type:

numpy.ndarray or dask.array.core.Array

Examples

>>> import numpy as np
>>> import sidpy
>>> struct_dtype = np.dtype({'names': ['r', 'g', 'b'],
>>>                          'formats': [np.float32, np.uint16, np.float64]})
>>> num_elems = 5
>>> real_val = np.concatenate((np.random.random(size=num_elems) * 1024,
>>>                            np.random.randint(0, high=1024, size=num_elems),
>>>                            np.random.random(size=num_elems) * 1024))
>>> print('Real valued dataset of shape {}:'.format(real_val.shape))
>>> print(real_val)
Real valued dataset of shape (15,):
[276.65339095 527.80665658 741.38145798 647.06743252 710.41729083
 380.         796.         504.         355.         985.
 960.70015068 567.47024098 881.25140299 105.48936013 933.13686734]
>>> comp_val = sidpy.dtype_utils.stack_real_to_compound(real_val, struct_dtype)
>>> print('Structured array of shape: {}'.format(comp_val.shape))
>>> print(comp_val)
Structured array of shape: (5,)
[(276.65338, 380, 960.70015068) (527.80664, 796, 567.47024098)
 (741.3815 , 504, 881.25140299) (647.06744, 355, 105.48936013)
 (710.4173 , 985, 933.13686734)]