Skip to content

einops.asnumpy

Convert a tensor of an imperative framework (i.e. numpy/cupy/torch/jax/etc.) to numpy.ndarray

Parameters:

Name Type Description Default
tensor Tensor

tensor of any known imperative framework

required

Returns:

Type Description
np_ndarray

numpy.ndarray, converted to numpy

Source code in einops/einops.py
734
735
736
737
738
739
740
741
742
743
744
def asnumpy(tensor: Tensor) -> np_ndarray:
    """
    Convert a tensor of an imperative framework (i.e. numpy/cupy/torch/jax/etc.) to `numpy.ndarray`

    Parameters:
        tensor: tensor of any known imperative framework

    Returns:
        `numpy.ndarray`, converted to numpy
    """
    return get_backend(tensor).to_numpy(tensor)