asarray#

named_arrays.asarray(a: ArrayT, dtype: None | type | dtype | str = None, order: None | str = None, *, like: None = None) → ArrayT#
named_arrays.asarray(a: int | float | complex | ndarray | Quantity | AbstractArray, dtype: None | type | dtype | str = None, order: None | str = None, *, like: LikeT = None) → LikeT

Converts the input to use only instances of numpy.ndarray as the underlying data.

This function does not convert an instance of named_arrays.AbstractArray to an instance of numpy.ndarray like you might expect from the documentation of numpy.asarray(). Instead, it recursively inspects the input, converting instances of named_arrays.AbstractImplicitArray to named_arrays.AbstractExplicitArray, and calling numpy.asarray() on the underlying data.

Parameters:
Returns:

Standardized interpretation of a, with all the underlying data expressed as instances of numpy.ndarray.

Return type:

out

Examples

Standardize a float

import named_arrays as na

na.asarray(2)
ScalarArray(
    ndarray=2,
    shape={},
)

Standardize a named_arrays.ScalarArray of float

na.asarray(na.ScalarArray(2))
ScalarArray(
    ndarray=2,
    shape={},
)

Standardize a named_arrays.Cartesian2dVectorArray of float

na.asarray(na.Cartesian2dVectorArray(2, 3))
Cartesian2dVectorArray(
    x=ScalarArray(
        ndarray=2,
        shape={},
    ),
    y=ScalarArray(
        ndarray=3,
        shape={},
    ),
)

See also

numpy.asarray()

Equivalent Numpy function

named_arrays.asanyarray()

Similar to this function, but allows numpy.ndarray subclasses to pass through.