NamedArrayBase#
- class penzai.core.named_axes.NamedArrayBase[source]#
Bases:
ABCBase class for named arrays and their transposed views.
Methods
all([axis, out, keepdims, where])Name-vectorized version of array method
all.any([axis, out, keepdims, where])Name-vectorized version of array method
any.argmax([axis, out, keepdims])Name-vectorized version of array method
argmax.argmin([axis, out, keepdims])Name-vectorized version of array method
argmin.argpartition(kth[, axis])Name-vectorized version of array method
argpartition.argsort([axis, kind, order, stable, descending])Name-vectorized version of array method
argsort.Converts into a
NamedArrayView, keeping positional axes.astype(dtype)Name-vectorized version of array method
astype.broadcast_like(other)Broadcasts a named array to be compatible with another.
broadcast_to([positional_shape, named_shape])Broadcasts a named array to a possibly-larger shape.
Ensures that the named axes are stored in a canonical order.
Checks that the names in the array are correct.
choose(choices[, out, mode])Name-vectorized version of array method
choose.clip([min, max, out])Name-vectorized version of array method
clip.compress(condition[, axis, out])Name-vectorized version of array method
compress.conj()Name-vectorized version of array method
conj.Name-vectorized version of array method
conjugate.cumprod([axis, dtype, out])Name-vectorized version of array method
cumprod.cumsum([axis, dtype, out])Name-vectorized version of array method
cumsum.diagonal([offset, axis1, axis2])Name-vectorized version of array method
diagonal.dot(b, *[, precision, preferred_element_type])Name-vectorized version of array method
dot.flatten([order])Name-vectorized version of array method
flatten.item(*args)Name-vectorized version of array method
item.max([axis, out, keepdims, initial, where])Name-vectorized version of array method
max.mean([axis, dtype, out, keepdims, where])Name-vectorized version of array method
mean.min([axis, out, keepdims, initial, where])Name-vectorized version of array method
min.nonzero(*[, size, fill_value])Name-vectorized version of array method
nonzero.order_as(*axis_order)Ensures that the named axes are stored in this order, keeping them named.
order_like(other)Ensures that this array's PyTree structure matches another array's.
prod([axis, dtype, out, keepdims, initial, ...])Name-vectorized version of array method
prod.ptp([axis, out, keepdims])Name-vectorized version of array method
ptp.ravel([order])Name-vectorized version of array method
ravel.repeat(repeats[, axis, total_repeat_length])Name-vectorized version of array method
repeat.reshape(*args[, order])Name-vectorized version of array method
reshape.round([decimals, out])Name-vectorized version of array method
round.searchsorted(v[, side, sorter, method])Name-vectorized version of array method
searchsorted.sort([axis, kind, order, stable, descending])Name-vectorized version of array method
sort.squeeze([axis])Name-vectorized version of array method
squeeze.std([axis, dtype, out, ddof, keepdims, where])Name-vectorized version of array method
std.sum([axis, dtype, out, keepdims, initial, ...])Name-vectorized version of array method
sum.swapaxes(axis1, axis2)Name-vectorized version of array method
swapaxes.tag(*names)Attaches names to the positional axes of an array or view.
tag_prefix(*axis_order)Attaches names to the first positional axes in an array or view.
take(indices[, axis, out, mode, ...])Name-vectorized version of array method
take.trace([offset, axis1, axis2, dtype, out])Name-vectorized version of array method
trace.transpose(*args)Name-vectorized version of array method
transpose.untag(*axis_order)Produces a positional view of the requested axis names.
untag_prefix(*axis_order)Adds the requested axes to the front of the array's positional axes.
unwrap(*names)Unwraps this array, possibly mapping axis names to positional axes.
var([axis, dtype, out, ddof, keepdims, where])Name-vectorized version of array method
var.view([dtype, type])Name-vectorized version of array method
view.Ensures a view is a
NamedArrayby moving positional axes.Attributes
Name-vectorized version of array method
T.The dtype of the wrapped array.
Name-vectorized version of array method
imag.Name-vectorized version of array method
mT.A mapping of axis names to their sizes.
A tuple of axis sizes for any anonymous axes.
Name-vectorized version of array method
real.Inherited Methods
(expand to view inherited methods)
__init__()- T#
Name-vectorized version of array method
T. Takes similar arguments asTbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __abs__()#
Name-vectorized version of
jax.Array.__abs__. Takes similar arguments asjax.Array.__abs__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __add__(b, /)#
Name-vectorized version of
jax.Array.__add__. Takes similar arguments asjax.Array.__add__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __and__(b, /)#
Name-vectorized version of
jax.Array.__and__. Takes similar arguments asjax.Array.__and__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __divmod__(y, /)#
Name-vectorized version of
jax.Array.__divmod__. Takes similar arguments asjax.Array.__divmod__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __floordiv__(b, /)#
Name-vectorized version of
jax.Array.__floordiv__. Takes similar arguments asjax.Array.__floordiv__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __ge__(b, /)#
Name-vectorized version of
jax.Array.__ge__. Takes similar arguments asjax.Array.__ge__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __getitem__(indexer) NamedArray | NamedArrayView[source]#
Retrieves slices from an indexer.
NamedArrayandNamedArrayViewcan be indexed in two different ways, depending on whether they have positional axes or not.If they do have positional axes, those positional axes can be indexed into using ordinary Numpy-style indexing. Indexing operations will be automatically vectorized over all of the named axes. For instance, an embedding lookup could look something like:
embedding_table.untag("vocab")[token_ids]
which first untagss the “vocab” named axis as positional, then indexes into that axis using another array (which can be a
NamedArrayor an ordinary array).If they do NOT have positional axes, the named axes can be sliced directly using dictionaries mapping names to indices or slices, e.g.:
my_array[{"position": 1, "feature": pz.slice[2:5]}]
Here
pz.slice[2:5]is syntactic sugar forslice(2, 5, None).- Parameters:
indexer – Either a normal Numpy-style indexer into the positional axes, or a mapping from a subset of axes names to the indices or slice it should return.
- Returns:
A slice of the array.
- __gt__(b, /)#
Name-vectorized version of
jax.Array.__gt__. Takes similar arguments asjax.Array.__gt__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __invert__()#
Name-vectorized version of
jax.Array.__invert__. Takes similar arguments asjax.Array.__invert__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __le__(b, /)#
Name-vectorized version of
jax.Array.__le__. Takes similar arguments asjax.Array.__le__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __lshift__(b, /)#
Name-vectorized version of
jax.Array.__lshift__. Takes similar arguments asjax.Array.__lshift__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __lt__(b, /)#
Name-vectorized version of
jax.Array.__lt__. Takes similar arguments asjax.Array.__lt__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __mod__(b, /)#
Name-vectorized version of
jax.Array.__mod__. Takes similar arguments asjax.Array.__mod__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __mul__(b, /)#
Name-vectorized version of
jax.Array.__mul__. Takes similar arguments asjax.Array.__mul__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __ne__(b, /)#
Name-vectorized version of
jax.Array.__ne__. Takes similar arguments asjax.Array.__ne__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __neg__()#
Name-vectorized version of
jax.Array.__neg__. Takes similar arguments asjax.Array.__neg__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __or__(b, /)#
Name-vectorized version of
jax.Array.__or__. Takes similar arguments asjax.Array.__or__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __pos__()#
Name-vectorized version of
jax.Array.__pos__. Takes similar arguments asjax.Array.__pos__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __pow__(b, /)#
Name-vectorized version of
jax.Array.__pow__. Takes similar arguments asjax.Array.__pow__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __radd__(y)[source]#
Name-vectorized version of
jax.Array.__radd__. Takes similar arguments asjax.Array.__radd__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rand__(y)[source]#
Name-vectorized version of
jax.Array.__rand__. Takes similar arguments asjax.Array.__rand__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rdivmod__(y)[source]#
Name-vectorized version of
jax.Array.__rdivmod__. Takes similar arguments asjax.Array.__rdivmod__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rfloordiv__(y)[source]#
Name-vectorized version of
jax.Array.__rfloordiv__. Takes similar arguments asjax.Array.__rfloordiv__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rlshift__(y)[source]#
Name-vectorized version of
jax.Array.__rlshift__. Takes similar arguments asjax.Array.__rlshift__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rmod__(y)[source]#
Name-vectorized version of
jax.Array.__rmod__. Takes similar arguments asjax.Array.__rmod__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rmul__(y)[source]#
Name-vectorized version of
jax.Array.__rmul__. Takes similar arguments asjax.Array.__rmul__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __ror__(y)[source]#
Name-vectorized version of
jax.Array.__ror__. Takes similar arguments asjax.Array.__ror__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rpow__(y)[source]#
Name-vectorized version of
jax.Array.__rpow__. Takes similar arguments asjax.Array.__rpow__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rrshift__(y)[source]#
Name-vectorized version of
jax.Array.__rrshift__. Takes similar arguments asjax.Array.__rrshift__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rshift__(b, /)#
Name-vectorized version of
jax.Array.__rshift__. Takes similar arguments asjax.Array.__rshift__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rsub__(y)[source]#
Name-vectorized version of
jax.Array.__rsub__. Takes similar arguments asjax.Array.__rsub__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rtruediv__(y)[source]#
Name-vectorized version of
jax.Array.__rtruediv__. Takes similar arguments asjax.Array.__rtruediv__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __rxor__(y)[source]#
Name-vectorized version of
jax.Array.__rxor__. Takes similar arguments asjax.Array.__rxor__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __sub__(b, /)#
Name-vectorized version of
jax.Array.__sub__. Takes similar arguments asjax.Array.__sub__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __truediv__(b, /)#
Name-vectorized version of
jax.Array.__truediv__. Takes similar arguments asjax.Array.__truediv__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- __xor__(b, /)#
Name-vectorized version of
jax.Array.__xor__. Takes similar arguments asjax.Array.__xor__but accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- all(axis: Axis = None, out: None = None, keepdims: bool = False, *, where: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
all. Takes similar arguments asallbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- any(axis: Axis = None, out: None = None, keepdims: bool = False, *, where: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
any. Takes similar arguments asanybut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- argmax(axis: int | None = None, out: None = None, keepdims: bool | None = None) Array[source]#
Name-vectorized version of array method
argmax. Takes similar arguments asargmaxbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- argmin(axis: int | None = None, out: None = None, keepdims: bool | None = None) Array[source]#
Name-vectorized version of array method
argmin. Takes similar arguments asargminbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- argpartition(kth: int, axis: int = -1) Array[source]#
Name-vectorized version of array method
argpartition. Takes similar arguments asargpartitionbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- argsort(axis: int | None = -1, kind: str | None = None, order: None = None, *, stable: bool = True, descending: bool = False) Array[source]#
Name-vectorized version of array method
argsort. Takes similar arguments asargsortbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- abstract as_namedarrayview() NamedArrayView[source]#
Converts into a
NamedArrayView, keeping positional axes.This function is usually not necessary for ordinary named-array manipulation, since
NamedArrayandNamedArrayViewdefine the same methods. However, it can be useful for simplifying library code that wishes to access the fields ofNamedArrayViewdirectly, or handle arbitrary named array objects without handling each case separately.Converting a
NamedArrayto aNamedArrayViewnever involves any device computations. (The reverse is not true).- Returns:
An equivalent
NamedArrayViewfor this array if it isn’t one already.
- astype(dtype: DTypeLike) Array[source]#
Name-vectorized version of array method
astype. Takes similar arguments asastypebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- broadcast_like(other: NamedArrayBase | jax.typing.ArrayLike) NamedArrayBase[source]#
Broadcasts a named array to be compatible with another.
- Parameters:
other – Another named array.
- Returns:
A named array that has the same positional and named shapes as
other(although it may also include extra named axes).
- broadcast_to(positional_shape: Sequence[int] = (), named_shape: Mapping[AxisName, int] | None = None) NamedArrayBase[source]#
Broadcasts a named array to a possibly-larger shape.
- Parameters:
positional_shape – Desired positional shape for the array. Will be broadcast using numpy broadcasting rules.
named_shape – Desired named shape for the array. Will be broadcast using
nmap-style vectorizing rules (e.g. new named axes will be introduced if missing, but length-1 axes will not be broadcast).
- Returns:
A named array that has the given positional and named shapes. Note that if this array has axis names that are not in
named_shape, these will be preserved in the answer as well.
- canonicalize() NamedArray[source]#
Ensures that the named axes are stored in a canonical order.
- Returns:
Equivalent
NamedArraywhose data array contains the positional axes followed by the named axes in sorted order.
- choose(choices: Sequence[ArrayLike], out: None = None, mode: str = 'raise') Array[source]#
Name-vectorized version of array method
choose. Takes similar arguments aschoosebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- clip(min: ArrayLike | None = None, max: ArrayLike | None = None, out: None = None) Array[source]#
Name-vectorized version of array method
clip. Takes similar arguments asclipbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- compress(condition: ArrayLike, axis: int | None = None, out: None = None) Array[source]#
Name-vectorized version of array method
compress. Takes similar arguments ascompressbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- conj() Array[source]#
Name-vectorized version of array method
conj. Takes similar arguments asconjbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- conjugate() Array[source]#
Name-vectorized version of array method
conjugate. Takes similar arguments asconjugatebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- cumprod(axis: Axis = None, dtype: DTypeLike | None = None, out: None = None) Array[source]#
Name-vectorized version of array method
cumprod. Takes similar arguments ascumprodbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- cumsum(axis: Axis = None, dtype: DTypeLike | None = None, out: None = None) Array[source]#
Name-vectorized version of array method
cumsum. Takes similar arguments ascumsumbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- diagonal(offset: int = 0, axis1: int = 0, axis2: int = 1) Array[source]#
Name-vectorized version of array method
diagonal. Takes similar arguments asdiagonalbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- dot(b: ArrayLike, *, precision: PrecisionLike = None, preferred_element_type: DTypeLike | None = None) Array[source]#
Name-vectorized version of array method
dot. Takes similar arguments asdotbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- abstract property dtype: np.dtype#
The dtype of the wrapped array.
- flatten(order: str = 'C') Array[source]#
Name-vectorized version of array method
flatten. Takes similar arguments asflattenbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- imag#
Name-vectorized version of array method
imag. Takes similar arguments asimagbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- item(*args) bool | int | float | complex[source]#
Name-vectorized version of array method
item. Takes similar arguments asitembut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- mT#
Name-vectorized version of array method
mT. Takes similar arguments asmTbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- max(axis: Axis = None, out: None = None, keepdims: bool = False, initial: ArrayLike | None = None, where: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
max. Takes similar arguments asmaxbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- mean(axis: Axis = None, dtype: DTypeLike | None = None, out: None = None, keepdims: bool = False, *, where: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
mean. Takes similar arguments asmeanbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- min(axis: Axis = None, out: None = None, keepdims: bool = False, initial: ArrayLike | None = None, where: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
min. Takes similar arguments asminbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- nonzero(*, size: int | None = None, fill_value: None | ArrayLike | tuple[ArrayLike, ...] = None) tuple[Array, ...][source]#
Name-vectorized version of array method
nonzero. Takes similar arguments asnonzerobut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- order_as(*axis_order: AxisName) NamedArray[source]#
Ensures that the named axes are stored in this order, keeping them named.
This function can be used if it is important for the axis names to appear in a consistent order, e.g. to ensure that two
NamedArrayinstances have exactly the same PyTree structure.If you want a canonical ordering for a named array that doesn’t involve knowing all the axis names in advance, you could do something like
array.order_as(*sorted(array.named_shape.keys())).See also
order_like.- Parameters:
*axis_order – Axis names in the order they should appear in the data array. Must be a permutation of all of the axis names in this array.
- Returns:
Equivalent
NamedArraywhose data array contains the positional axes followed by the named axes in the given order.
- order_like(other: NamedArray | NamedArrayView) NamedArray | NamedArrayView[source]#
Ensures that this array’s PyTree structure matches another array’s.
This can be used to ensure that one named array has the same PyTree structure as another, so that the two can be jointly processed by non-namedarray-aware tree functions (e.g.
jax.tree_utilfunctions,jax.lax.cond,jax.jvp, etc).To ensure compatibility of entire PyTrees, you can use something like:
jax.tree_util.tree_map( lambda a, b: a.order_like(b), tree1, tree2, is_leaf=pz.nx.is_namedarray, )
- Parameters:
other – Another named array or named array view. Must have the same set of named axes as this one. If this is a
NamedArrayView, must also have the same positional axes.- Returns:
A new
NamedArrayorNamedArrayViewthat has the content ofselfbut is possibly transposed to have the same PyTree structure asother(as long as the arrays have the same shape).
- prod(axis: Axis = None, dtype: DTypeLike | None = None, out: None = None, keepdims: bool = False, initial: ArrayLike | None = None, where: ArrayLike | None = None, promote_integers: bool = True) Array[source]#
Name-vectorized version of array method
prod. Takes similar arguments asprodbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- ptp(axis: Axis = None, out: None = None, keepdims: bool = False) Array[source]#
Name-vectorized version of array method
ptp. Takes similar arguments asptpbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- ravel(order: str = 'C') Array[source]#
Name-vectorized version of array method
ravel. Takes similar arguments asravelbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- real#
Name-vectorized version of array method
real. Takes similar arguments asrealbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- repeat(repeats: ArrayLike, axis: int | None = None, *, total_repeat_length: int | None = None) Array[source]#
Name-vectorized version of array method
repeat. Takes similar arguments asrepeatbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- reshape(*args: Any, order: str = 'C') Array[source]#
Name-vectorized version of array method
reshape. Takes similar arguments asreshapebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- round(decimals: int = 0, out: None = None) Array[source]#
Name-vectorized version of array method
round. Takes similar arguments asroundbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- searchsorted(v: ArrayLike, side: str = 'left', sorter: None = None, *, method: str = 'scan') Array[source]#
Name-vectorized version of array method
searchsorted. Takes similar arguments assearchsortedbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- sort(axis: int | None = -1, kind: str | None = None, order: None = None, *, stable: bool = True, descending: bool = False) Array[source]#
Name-vectorized version of array method
sort. Takes similar arguments assortbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- squeeze(axis: int | Sequence[int] | None = None) Array[source]#
Name-vectorized version of array method
squeeze. Takes similar arguments assqueezebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- std(axis: Axis = None, dtype: DTypeLike | None = None, out: None = None, ddof: int = 0, keepdims: bool = False, *, where: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
std. Takes similar arguments asstdbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- sum(axis: Axis = None, dtype: DTypeLike | None = None, out: None = None, keepdims: bool = False, initial: ArrayLike | None = None, where: ArrayLike | None = None, promote_integers: bool = True) Array[source]#
Name-vectorized version of array method
sum. Takes similar arguments assumbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- swapaxes(axis1: int, axis2: int) Array[source]#
Name-vectorized version of array method
swapaxes. Takes similar arguments asswapaxesbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- abstract tag(*names) NamedArray[source]#
Attaches names to the positional axes of an array or view.
- Parameters:
*names – Axis names to assign to each positional axis in the array or view. Must be the same length as
positional_shape; if you only want to tag a subset of axes, usetag_prefixinstead.- Raises:
ValueError – If the names are invalid, or if they aren’t the same length as
positional_shape.- Returns:
A NamedArray with the given names assigned to the positional axes, and no remaining positional axes.
- tag_prefix(*axis_order: AxisName) NamedArray | NamedArrayView[source]#
Attaches names to the first positional axes in an array or view.
This is a version of
tagthat allows you to name only a subset of the array’s positional axes.- Parameters:
*axis_order – Axis names to make positional, in the order they should appear in the positional view.
- Returns:
A NamedArray or view with the given names assigned to the first positional axes, and whose positional shape includes only the suffix of axes that have not been given names.
- take(indices: ArrayLike, axis: int | None = None, out: None = None, mode: str | None = None, unique_indices: bool = False, indices_are_sorted: bool = False, fill_value: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
take. Takes similar arguments astakebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- trace(offset: int = 0, axis1: int = 0, axis2: int = 1, dtype: DTypeLike | None = None, out: None = None) Array[source]#
Name-vectorized version of array method
trace. Takes similar arguments astracebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- transpose(*args: Any) Array[source]#
Name-vectorized version of array method
transpose. Takes similar arguments astransposebut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- abstract untag(*axis_order: AxisName) NamedArray | NamedArrayView[source]#
Produces a positional view of the requested axis names.
untagcan only be called on aNamedArrayorNamedArrayViewthat does not have any positional axes. It produces a newNamedArrayViewwhere the axes with the requested names (the arguments to this function) are now treated as positional in the given order.If you want to use
untagon an array that already has positional axes, you can useuntag_prefixinstead.- Parameters:
*axis_order – Axis names to make positional, in the order they should appear in the positional view.
- Raises:
ValueError – If this array already has positional axes, or if the provided axis ordering is not valid.
- Returns:
A view with the given axes treated as positional for the purposes of later calls to
apply,nmap, orwith_positional_prefix. If passed an empty axis order, returns an ordinary NamedArray with no positional axes.
- untag_prefix(*axis_order: AxisName) NamedArray | NamedArrayView[source]#
Adds the requested axes to the front of the array’s positional axes.
This is a version of
untagthat can be called on NamedArrays or NamedArrayViews that already have positional axes.- Parameters:
*axis_order – Axis names to make positional, in the order they should appear in the positional view.
- Returns:
A view with the given axes treated as positional, followed by the existing positional axes.
- abstract unwrap(*names: AxisName) jax.Array[source]#
Unwraps this array, possibly mapping axis names to positional axes.
Unwrap can be called either on arrays with no named axes, or arrays with no positional axes (in which case
namesshould be a permutation of its axis names).- Parameters:
*names – Sequence of axis names to map to positional axes, if this array has named axes. Shortand for
untag(*names).unwrap().- Returns:
An equivalent ordinary positional array.
- Raises:
ValueError – If the array has a mixture of positional and named axes, or if the names do not match the named axes.
- var(axis: Axis = None, dtype: DTypeLike | None = None, out: None = None, ddof: int = 0, keepdims: bool = False, *, where: ArrayLike | None = None) Array[source]#
Name-vectorized version of array method
var. Takes similar arguments asvarbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- view(dtype: DTypeLike | None = None, type: None = None) Array[source]#
Name-vectorized version of array method
view. Takes similar arguments asviewbut accepts and returns NamedArrays (or NamedArrayViews) in place of regular arrays.
- abstract with_positional_prefix() NamedArray[source]#
Ensures a view is a
NamedArrayby moving positional axes.The resulting
NamedArrayhas the same named and positional shapes as this object, but the data array may be transposed so that all the positional axes are in the front. This makes it possible to manipulate those prefix axes safely usingjax.tree_utilor scan/map over them using JAX control flow primitives.- Returns:
An equivalent
NamedArrayfor this view, or the originalNamedArrayif it already was one.