bundles / numpy 2.4.3 / numpy / _core / shape_base / _concatenate_shapes
function
numpy._core.shape_base:_concatenate_shapes
source: /numpy/_core/shape_base.py :638
Signature
def _concatenate_shapes ( shapes , axis ) Summary
Given array shapes, return the resulting shape and slices prefixes.
Extended Summary
These help in nested concatenation.
Returns
: shape: tuple of intThis tuple satisfies
shape, _ = _concatenate_shapes([arr.shape for shape in arrs], axis) shape == concatenate(arrs, axis).shape
: slice_prefixes: tuple of (slice(start, end), )For a list of arrays being concatenated, this returns the slice in the larger array at axis that needs to be sliced into.
For example, the following holds
ret = concatenate([a, b, c], axis) _, (sl_a, sl_b, sl_c) = concatenate_slices([a, b, c], axis) ret[(slice(None),) * axis + sl_a] == a ret[(slice(None),) * axis + sl_b] == b ret[(slice(None),) * axis + sl_c] == c
These are called slice prefixes since they are used in the recursive blocking algorithm to compute the left-most slices during the recursion. Therefore, they must be prepended to rest of the slice that was computed deeper in the recursion.
These are returned as tuples to ensure that they can quickly be added to existing slice tuple without creating a new tuple every time.
Aliases
-
numpy._core.shape_base._concatenate_shapes