Class np.lib.array_utils
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
NumPy's numpy.lib.array_utils (NumPy 2.0's public home of three helpers that lived in
numpy.lib.utils / numpy.core.multiarray): byte_bounds(NDArray),
normalize_axis_index(int, int, string) and normalize_axis_tuple(NDAxis, int, string, bool), over the same statements every
NumSharp axis-taking function runs (Shape's axis checks), so their texts are NumPy's.
[ModuleName("np.lib.array_utils")]
public static class np.lib.array_utils
- Inheritance
-
np.lib.array_utils
- Inherited Members
Methods
byte_bounds(NDArray)
NumPy's byte_bounds(a): the first byte address a reaches and the address one
past its last byte - the memory range its elements occupy, whatever its strides (a reversed axis moves
the low end, a broadcast axis adds nothing).
public static (long low, long high) byte_bounds(NDArray a)
Parameters
aNDArrayThe array (any layout, a view included).
Returns
- (long low, long high)
The
(low, high)byte addresses:high - lowis the span (size * itemsizefor a C-contiguous array, 0 for an empty one).
Remarks
NumPy's statements over a.array_interface: a C-contiguous array reports no strides, so its
high end is data + size * itemsize; any other array adds (n - 1) * stride per axis to the
low end (a negative stride) or the high end, then one item. The addresses are this process's, as
NumPy's are, and stay valid only while the array's buffer lives.
Exceptions
- ArgumentNullException
ais null.
normalize_axis_index(int, int, string)
NumPy's normalize_axis_index(axis, ndim, msg_prefix=None): axis wrapped into
[0, ndim), or NumPy's AxisError naming it.
public static int normalize_axis_index(int axis, int ndim, string msg_prefix = null)
Parameters
axisintThe axis; negative values count from the end.
ndimintThe rank the axis addresses.
msg_prefixstringA prefix NumPy prints before the text (
"axes"givesaxes: axis 3 is out of bounds for array of dimension 3), or null for none.
Returns
- int
The non-negative axis.
Exceptions
- AxisError
axisis outside[-ndim, ndim):axis 3 is out of bounds for array of dimension 3.
normalize_axis_tuple(NDAxis, int, string, bool)
NumPy's normalize_axis_tuple(axis, ndim, argname=None, allow_duplicate=False): every axis of
axis wrapped into [0, ndim), then NumPy's repeated-axis refusal unless
allow_duplicate.
public static int[] normalize_axis_tuple(NDAxis axis, int ndim, string argname = null, bool allow_duplicate = false)
Parameters
axisNDAxisOne axis or a tuple of axes (NumPy's int or iterable of ints).
ndimintThe rank the axes address.
argnamestringThe argument name: the AxisError's prefix and the repeat text's
repeated axis in; null gives the plain texts.axesargumentallow_duplicateboolWhen false (NumPy's default) a repeated axis raises; when true repeats are kept in order.
Returns
- int[]
The normalized axes, one per input entry, in input order (NumPy's tuple).
Exceptions
- AxisError
An axis is out of range (every range is checked before any repeat).
- ValueError
A repeated axis and
allow_duplicatefalse (repeated axis).
normalize_axis_tuple(int, int, string, bool)
normalize_axis_tuple(NDAxis, int, string, bool) with one int axis: the overload a
C# integer binds (the owner's kept integer form beside every NumPy-axis member).
public static int[] normalize_axis_tuple(int axis, int ndim, string argname = null, bool allow_duplicate = false)
Parameters
axisintThe axis; negative values count from the end.
ndimintThe rank the axis addresses.
argnamestringThe argument name for the AxisError's prefix, or null.
allow_duplicateboolUnused for one axis (it cannot repeat); NumPy's signature.
Returns
- int[]
The one-element tuple of the normalized axis.
Exceptions
- AxisError
axisis out of range.
normalize_axis_tuple(int[], int, string, bool)
normalize_axis_tuple(NDAxis, int, string, bool) with an int[] of axes (the owner's
kept array form beside every NumPy-axis member).
public static int[] normalize_axis_tuple(int[] axis, int ndim, string argname = null, bool allow_duplicate = false)
Parameters
axisint[]The axes (not null; never modified).
ndimintThe rank the axes address.
argnamestringThe argument name for the texts, or null.
allow_duplicateboolWhether a repeated axis is kept.
Returns
- int[]
The normalized axes in input order.
Exceptions
- ArgumentNullException
axisis null.- AxisError
An axis is out of range.
- ValueError
A repeated axis and
allow_duplicatefalse.