moveaxis_to_start

moveaxis_to_start#

moveaxis_to_start = functools.partial(<function moveaxis>, destination=0)#

numpy.moveaxis() with destination=0 pre-applied.

Moves a nominated source axis to position 0 (the leading axis) while keeping all other axes in their original relative order. This is used throughout the polydata builder functions in pyvisual.core.mesh3d to bring the “stack” axis to the front before reshaping, enabling uniform downstream iteration over batches of curves or surface slices.

For example, if a fieldline array has shape (N_r, N_lines) with the line index on axis 1, moveaxis_to_start(arr, 1) returns a view of shape (N_lines, N_r) without copying data.

Parameters:
anp.ndarray

Input array.

sourceint | Sequence[int]

Original position(s) of the axis (or axes) to move.

**kwargs

Any additional keyword arguments accepted by numpy.moveaxis(). destination is already fixed to 0 and cannot be overridden.

Returns:
outnp.ndarray

View of a with the specified axis moved to position 0.

See also

numpy.moveaxis()

The underlying NumPy function.

ij_meshgrid

Companion partial used to broadcast 1-D coordinate arrays before axis reordering.

Examples

Move the line-index axis of a fieldline coordinate array to the front:

>>> import numpy as np
>>> arr = np.zeros((100, 5, 3))  # shape: (N_r, N_lines, xyz)
>>> out = moveaxis_to_start(arr, 1)
>>> out.shape
(5, 100, 3)