Table of Contents

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

a NDArray

The array (any layout, a view included).

Returns

(long low, long high)

The (low, high) byte addresses: high - low is the span (size * itemsize for 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

a is 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

axis int

The axis; negative values count from the end.

ndim int

The rank the axis addresses.

msg_prefix string

A prefix NumPy prints before the text ("axes" gives axes: axis 3 is out of bounds for array of dimension 3), or null for none.

Returns

int

The non-negative axis.

Exceptions

AxisError

axis is 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

axis NDAxis

One axis or a tuple of axes (NumPy's int or iterable of ints).

ndim int

The rank the axes address.

argname string

The argument name: the AxisError's prefix and the repeat text's repeated axis in axes argument; null gives the plain texts.

allow_duplicate bool

When 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_duplicate false (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

axis int

The axis; negative values count from the end.

ndim int

The rank the axis addresses.

argname string

The argument name for the AxisError's prefix, or null.

allow_duplicate bool

Unused for one axis (it cannot repeat); NumPy's signature.

Returns

int[]

The one-element tuple of the normalized axis.

Exceptions

AxisError

axis is 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

axis int[]

The axes (not null; never modified).

ndim int

The rank the axes address.

argname string

The argument name for the texts, or null.

allow_duplicate bool

Whether a repeated axis is kept.

Returns

int[]

The normalized axes in input order.

Exceptions

ArgumentNullException

axis is null.

AxisError

An axis is out of range.

ValueError

A repeated axis and allow_duplicate false.