asarray#

named_arrays.asarray(a: ArrayT, dtype: None | type | dtype | str = None, order: None | str = None, *, like: None = None) ArrayT#
named_arrays.asarray(a: ArrayT, 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:
  • a (ArrayT) – Input array to be converted

  • dtype (None | type | dtype | str) – Data type of output, usually inferred from the input.

  • order (None | str) – Memory layout. See the documentation of numpy.asarray() for more information.

  • like (None | LikeT) – Optional reference object. If provided, the result will be defined by this object.

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,
    axes=(),
)

Standardize a named_arrays.ScalarArray of float

na.asarray(na.ScalarArray(2))
ScalarArray(
    ndarray=2,
    axes=(),
)

Standardize a named_arrays.Cartesian2dVectorArray of float

na.asarray(na.Cartesian2dVectorArray(2, 3))
Cartesian2dVectorArray(
    x=ScalarArray(
        ndarray=2,
        axes=(),
    ),
    y=ScalarArray(
        ndarray=3,
        axes=(),
    ),
)

See also

numpy.asarray()

Equivalent Numpy function

named_arrays.asanyarray()

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