asanyarray#

named_arrays.asanyarray(a: ArrayT, dtype: None | type | dtype | str = None, order: None | str = None, *, like: None = None) → ArrayT#
named_arrays.asanyarray(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 subclasses as the underlying data.

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

Parameters:
Returns:

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

Return type:

out

Examples

Standardize an instance of astropy.units.Quantity

import astropy.units as u
import named_arrays as na

na.asanyarray(2 * u.mm)
ScalarArray(
    ndarray=2. mm,
    shape={},
)

See also

numpy.asanyarray()

Equivalent Numpy function

named_arrays.asarray()

Similar to this function but converts instances of numpy.ndarray subclasses back to instances of numpy.ndarray.