shape#

named_arrays.shape(a)#

Compute the shape of the given array.

In numpy, the shape of an array is a tuple of integers. For this package, each axis is characterized by a name instead of its position, so the shape is a dict where the keys are the axis names and the values are number of elements along each axis.

If a is an arbitrarily-nested structure (dict, list, tuple, or dataclasses instance), the result is the broadcast_shapes() of the shapes of all the array-like leaves, so a container of compatible arrays reports their combined broadcasted shape.

Parameters:

a (int | float | complex | ndarray | Quantity | AbstractArray) – The array, or nested structure of arrays, to compute the shape of.

Return type:

dict[str, int]

Examples

import named_arrays as na

x = na.arange(0, 5, axis="x")
y = na.arange(0, 3, axis="y")

# the broadcasted shape of every array-like leaf
na.shape({"foo": x, "bar": y})
{'x': 5, 'y': 3}