abracudabra.conversion.carray#
Convert to numpy or cupy arrays.
Functions#
|
Convert a torch tensor to a numpy array. |
|
Convert a numpy/cupy array to a numpy/cupy array. |
|
|
|
|
|
|
|
Convert an array, series, or dataframe to a numpy array. |
Module Contents#
- abracudabra.conversion.carray._torch_to_array(tensor: torch.Tensor, /, device: str | abracudabra.device.base.Device | None = None) abracudabra.annotations.Array [source]#
Convert a torch tensor to a numpy array.
- abracudabra.conversion.carray._array_to_array(array: abracudabra.annotations.Array, /, device: str | abracudabra.device.base.Device | None = None) abracudabra.annotations.Array [source]#
Convert a numpy/cupy array to a numpy/cupy array.
The array is converted to the desired device if specified.
- abracudabra.conversion.carray._pandas_frame_to_array(frame: pandas.Index | pandas.Series[Any] | pandas.DataFrame, /, device: str | abracudabra.device.base.Device | None = None) abracudabra.annotations.Array [source]#
- abracudabra.conversion.carray._cudf_frame_to_array(frame: cudf.Index | cudf.Series | cudf.DataFrame, /, device: str | abracudabra.device.base.Device | None = None) abracudabra.annotations.Array [source]#
- abracudabra.conversion.carray._any_to_array(sequence: object, /, device: str | abracudabra.device.base.Device | None) abracudabra.annotations.Array [source]#
- abracudabra.conversion.carray.to_array(sequence: abracudabra.annotations.Array | abracudabra.annotations.Series | abracudabra.annotations.DataFrame | torch.Tensor, /, device: str | abracudabra.device.base.Device | None = None, *, strict: bool = False) abracudabra.annotations.Array [source]#
Convert an array, series, or dataframe to a numpy array.
- Parameters:
sequence – The sequence to convert.
device – The device to convert the sequence to. If None, the sequence stays on the same device.
strict – Whether to raise an error if the sequence is not a valid type. A numpy/cupy array, pandas/cudf series or dataframe, or torch tensor are valid types. If False, the sequence is converted to a numpy/cupy array if possible, but it might raise an error if the conversion is not possible.
- Returns:
A numpy/cupy array.