asanyarray#

named_arrays.asanyarray(a: ArrayT, dtype: None | type | dtype | str = None, order: None | str = None, *, like: None = None) ArrayT#
named_arrays.asanyarray(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 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:
  • 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.asanyarray() 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 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,
    axes=(),
)

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.