ndarrays_to_tensors

ndarrays_to_tensors#

ptyrad.utils.common.ndarrays_to_tensors(data, device='cuda')[source]#

Recursively convert all numpy.ndarray instances in any nested structure (including lists, dicts, and tuples) into torch.Tensor on the specified device.

This function supports both single objects and arbitrarily nested container types. Non-array types are returned unchanged.

Parameters:
  • data – Input data which can be nested dict, list, tuple, np.ndarray, or other.

  • device (str) – Device on which to place the tensors. Default is ‘cuda’.

Returns:

The same structure with numpy.ndarray replaced by torch.Tensor.