Class NDMaskedArray
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
A NumPy numpy.ma.MaskedArray: an NDArray of data paired with a boolean mask
marking elements to ignore. Distinct from a plain NDArray precisely because
operations SKIP the masked elements' influence and preserve their mask into the result — reach for
it only when some entries are invalid/missing and must not participate in arithmetic while keeping
the array's shape.
The mask is stored as null when there is no mask (NumPy's nomask fast path), which is
what keeps an all-valid masked array as cheap as the underlying NDArray. The data is
never null. This type deliberately does NOT own/dispose its arrays — it holds references the way
NumPy's MaskedArray holds views over its base — so the caller keeps the source arrays alive.
public class NDMaskedArray
- Inheritance
-
NDMaskedArray
- Derived
- Inherited Members
Constructors
NDMaskedArray(NDArray, NDArray, NDArray)
Wraps a data array and (optional) mask into a masked array WITHOUT copying either — the arrays
are aliased, so later writes to them are visible here and vice-versa. Pass mask
null for the no-mask (nomask) fast path.
public NDMaskedArray(NDArray data, NDArray mask, NDArray fill_value = null)
Parameters
dataNDArrayThe data buffer (aliased, not copied). Must not be null.
maskNDArrayThe boolean mask (True = masked), or null for no mask. When non-null it should already match
data's shape; callers building it via broadcasting materialize it first.fill_valueNDArrayThe stored fill array (NumSharp.NDMaskedArray._fill_value) — already converted to
data's dtype (StoreFill(object, DType); it stays in the ambient scope with the new data and mask, so a scoped builder must yield it with the result), or a source's stored array this one SHARES (NumPy's_update_from) — or null for NumPy's None (the getter materializes the default).
Remarks
The constructor a subclass of the masked array chains to. Footgun: unlike NumPy's MaskedArray(data, mask)
it validates nothing but data - a mask of another shape or dtype, or a fill value of another
dtype, is stored as given and fails later in whatever reads it. To build a masked array from user data, use
np.ma.array / np.ma.masked_array, which check, broadcast and convert as NumPy does.
Exceptions
- ArgumentNullException
datais null.
Properties
this[object[]]
Indexes the masked array (NumPy's x[key] / x[key] = value). GET returns the bare
scalar for an index that reduces to a single UNMASKED element, the NDMasked
singleton for a single MASKED element, or a sub-NDMaskedArray otherwise (a VIEW sharing
memory for a basic slice, a COPY for a fancy/boolean index — matching NumPy). SET accepts a scalar,
array-like, NDArray, NDMaskedArray, or the masked singleton
(which masks the slots without touching their data).
public object this[params object[] indices] { get; set; }
Parameters
indicesobject[]Mixed index objects — ints (coordinate), slice strings ("1:3"), Slices, boolean/integer NDArray masks/fancy indices — exactly as NDArray's own
this[params object[]]accepts.
Property Value
- object
A boxed scalar, the
maskedsingleton, or a NDMaskedArray. A sub-array inherits this array's fill value and hard-mask flag (see UpdateFrom(NDMaskedArray)), so a slice of a hard-masked array is itself hard and a write through it cannot unmask the parent.
Remarks
Returns object because NumPy's indexer is polymorphic (scalar vs masked vs
sub-array) and a C# indexer cannot switch its type on the runtime index; a slice read is a
NDMaskedArray to cast. When a masking write through a VIEW of a nomask array creates
the view's mask, that mask is local to the view: the parent has no mask buffer for it to alias, so the
parent stays unmasked. NumPy 2.4.2 behaves the same way.
T
Transpose (reverse all axes); NumPy's MaskedArray.T. Data and mask are transposed
alike, so the mask stays aligned. A view — no data is moved.
public NDMaskedArray T { get; }
Property Value
base
The array this masked array is a view of (NumPy's MaskedArray.base): a NumPy masked array is an ndarray
VIEW of its data, so its base is that data - the very array passed to np.ma.array(d) when no copy was
made (ReferenceEquals(np.ma.array(d).@base, d), NumPy's ma.array(d).base is d), the masked
array's own data array otherwise. Never null, unlike an owning NDArray's @base.
public NDArray @base { get; }
Property Value
Remarks
Footgun: it is the stored data object itself, not a view of it (identity is NumPy's point): disposing it releases this masked array's data. API-parity batch 12.
baseclass
The class of the underlying data (NumPy's read-only MaskedArray.baseclass); always
NDArray in NumSharp, whose masked array wraps a plain NDArray.
public Type baseclass { get; }
Property Value
data
The underlying data array (NumPy's MaskedArray.data): a VIEW of the data, a new one per read
(ndarray.view(self, self._baseclass)), so it never owns its buffer (flags.owndata is False) and a
write through it reaches the masked array. Masked positions are included with whatever value the producing op
left; use filled(object) to substitute them.
public NDArray data { get; }
Property Value
Remarks
Each read allocates a view object; library code reads the field (_data) instead.
device
The device the masked array lives on: always "cpu" (NumPy's MaskedArray.device, inherited
from ndarray; NumSharp is single-device and CPU-resident). API-parity batch 12.
public string device { get; }
Property Value
dtype
The data dtype (NumPy's .dtype); the mask is always boolean regardless.
public DType dtype { get; }
Property Value
fill_value
The value filled(object) substitutes for masked elements (NumPy's settable
MaskedArray.fill_value): the element of the stored fill array, NumPy's self._fill_value[()] — a
boxed scalar of the STORED array's dtype (NumPy's NumPy scalar: an sbyte for an int8 fill, a
long for the int64 default), or the array itself for NumPy's deprecated non-scalar fill. Never
null.
public object fill_value { get; set; }
Property Value
Remarks
NumPy's method forms get_fill_value()/set_fill_value() are NOT offered as
instance methods: a C# property named fill_value already reserves those exact accessor names,
so use the property (a.fill_value / a.fill_value = v) or the module-level
set_fill_value(object, object).
The state is NumPy's, for every dtype, and it depends on call history. An array whose fill was never
set or read stores nothing; the getter then MATERIALIZES the default (self._fill_value =
_check_fill_value(None, self.dtype), DefaultFill(DType)), which has the DEFAULT's
own dtype: int64 999999 for an int8 array, uint64 for an unsigned one, float64 1e20 for float16 / float32,
np.array('N/A') (<U3) for text. A set value is converted to the DATA's dtype first
(CheckFillValue(object, DType): 5.7 on int8 is 5, 300 raises) and then stored
when nothing is stored, or written INTO the stored array (_fill_value[()] = target, an unsafe cast at
the stored dtype and width). So x.fill_value = 5 on a fresh int8 array reads back sbyte
5, but after a read of the default it reads back long 5; setting null after fill_value = 5
writes 999999 into the int8 fill (63); text set into a materialized 'N/A' is cut to three characters.
The stored array may be SHARED with arrays derived from this one (views, the _arraymethod family, the
masked ufuncs — NumPy's _update_from), and a set reaches all of them, as NumPy's does; constructors,
astype(DType, char, string, bool), view(DType, object) and copies store a converted copy instead
(FinalizeFrom(NDMaskedArray), NumPy's __array_finalize__). Reading the getter (or printing the array,
whose repr reads it) therefore changes what a later astype(DType, char, string, bool) converts: the default 1e20 of a
float64 array becomes long.MinValue in int64 once it was read, while an unread array's int64 copy
starts from its own default 999999.
Exceptions
- TypeError
Set: a string for a numeric array (
Cannot set fill value of string with array of dtype float64), a C# number the dtype cannot hold (Cannot convert fill_value 300 to dtype int8), a complex for a real dtype (Python's ownint()/float()text), text the array's class cannot encode or decode, or bytes / a text array a numeric array cannot parse (Cannot convert fill_value b'x' to dtype float64; a number formats into a text array, which cannot fail).- ValueError
Set: an array with dimensions written into a stored 0-d fill (NumPy's element assignment:
setting an array element with a sequence., even for one element; a bool fill takes a one-element array), or into a stored N-d fill it does not broadcast to.- AttributeError
Get or set on the masked singleton: NumPy's
attributes of masked are not writeable(its getter's materialization is an attribute write).
flat
A flattened row-major VIEW of the array (mask flattened alike). NOTE: this follows NumSharp's
flat house convention — a raveled ARRAY (a view for a contiguous source, a
copy otherwise) — NOT NumPy's flat iterator object. It writes through only when
ravel(char) returned a view (a C-contiguous source).
public NDMaskedArray flat { get; }
Property Value
hardmask
Whether the mask is HARD (NumPy's read-only hardmask property): true once
harden_mask() has been called, so a plain-value assignment can no longer unmask a slot;
false (the default) after soften_mask(). See NumSharp.NDMaskedArray._hardmask for the honored
assignment paths and the propagation-scope limits.
public bool hardmask { get; }
Property Value
Remarks
NumPy's sharedmask flag is deliberately NOT offered: NumSharp cannot track whether a
mask is shared (a view/real/imag/view(DType, object) aliases it), and
no fixed value is faithful — NumPy reports True right after array(data, mask=…) yet False after
an op or unshare_mask(). Since a bogus False would invite mutating a shared mask, just
call unshare_mask() before an in-place mask write on a possibly-aliased array.
imag
The imaginary part as a masked array (NumPy's MaskedArray.imag), built like real: the
mask COPIED, soft, the default fill value. For a non-complex dtype every element is 0.
public NDMaskedArray imag { get; }
Property Value
itemsize
Bytes per data element (NumPy's .itemsize). Describes the DATA buffer; the mask is a
separate boolean array and does not contribute.
public int itemsize { get; }
Property Value
mT
Matrix transpose — swaps the last two axes (NumPy's MaskedArray.mT); requires rank ≥ 2. A NEW
masked array (soft, the default fill value) whose mask is a swapped VIEW of this one's.
public NDMaskedArray mT { get; }
Property Value
Exceptions
- ArgumentException
The array is rank < 2.
mask
The boolean mask (NumPy's MaskedArray.mask): a VIEW of the mask array, a new one per read
(self._mask.view(), so the caller cannot change its dtype or shape in place), or the shared
nomask sentinel (a 0-d False) when no element is masked — NumPy yields
nomask rather than a full False array in that case.
public NDArray mask { get; }
Property Value
Remarks
A write through the view reaches the mask. Each read of an array mask allocates a view object; library
code reads the field (_mask) instead.
nbytes
Total bytes consumed by the DATA (NumPy's .nbytes): size × itemsize. Matches
NumPy in EXCLUDING the mask's bytes — the mask is tracked separately, so a masked array reports the
same nbytes as its unmasked data.
public long nbytes { get; }
Property Value
ndim
Number of dimensions of the data (NumPy's .ndim).
public int ndim { get; }
Property Value
real
The real part as a masked array (NumPy's MaskedArray.real): self._data.real.view(type(self))
with setmask(self._mask) — the mask is COPIED, and the result is soft with the default fill value (the
view of a plain array inherits nothing).
public NDMaskedArray real { get; }
Property Value
recordmask
The record mask (NumPy's MaskedArray.recordmask): for a non-structured array — every
array in NumSharp, which has no structured dtypes — this is just the element mask (the
nomask sentinel when nothing is masked).
public NDArray recordmask { get; }
Property Value
shape
The data shape as a long[] (NumPy's .shape; NumSharp dimensions are 64-bit).
Data and mask share this shape.
public long[] shape { get; }
Property Value
- long[]
size
Total element count (NumPy's .size).
public long size { get; }
Property Value
strides
Per-axis strides of the DATA, in BYTES (NumPy's .strides; NumSharp reports byte strides
to match NumPy). The mask, when present, shares the data's shape but has its own boolean strides.
public long[] strides { get; }
Property Value
- long[]
typecode
Element type code of the data, for dtype dispatch.
public NPTypeCode typecode { get; }
Property Value
Methods
ToString()
The NumPy str() form of the masked array — the data with masked slots shown inline as the
masked_print_option token (default --), e.g.
[1 -- 3 --]. This is a BYTE-EXACT port of NumPy 2.4.2's MaskedArray.str (see
ToString(bool) for the full algorithm/caveats). Mirrors ToString()'s
convention: ToString() is the str form, ToString(true) the repr form.
public override string ToString()
Returns
- string
The masked
str()rendering.
ToString(bool)
Renders the masked array as NumPy 2.4.2 does — a BYTE-EXACT port of MaskedArray.str
(flat false) and MaskedArray.repr (flat true).
Why masked prints look UNALIGNED. When a mask is present and
masked_print_option is enabled, NumPy converts the data to an OBJECT
array, substitutes the display token at masked slots, and prints via object-array formatting — each
element its own Python-scalar repr with NO numeric column alignment (so [1 -- 3 --], not the
padded numeric form). A nomask array (or a disabled print option, which fills the masked slots
with the fill value instead) prints the numeric array with normal alignment.
repr envelope. The masked_array(data=…, mask=…, fill_value=…[, dtype=…]) template,
indents, one-row-vs-multi-row layout, and the dtype=-shown rule (non-implied dtype, or an
all-masked/empty array) all match NumPy exactly. The fill_value= line is byte-exact for the
DEFAULT fill value across every dtype (including the np.<type>(value) wrapper NumPy 2.x
shows when the fill's promoted dtype differs from the data dtype); a caller-SET custom fill of a
mismatched dtype is rendered against the data dtype and may differ in that one line only.
public string ToString(bool flat)
Parameters
flatboolFalse ⇒ the NumPy
str()form (data only); true ⇒ therepr()form.
Returns
- string
The rendered string.
Remarks
Scoped ([NDScoped]): printing a masked array builds throwaway arrays (the filled copy a
disabled print option renders, the np.all(mask) probe of the dtype= rule); all of them are
reclaimed before the string is returned.
all(int, NDMaskedArray, bool)
The owner's kept int form of all(NDAxis?, NDMaskedArray, bool).
public NDMaskedArray all(int axis, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked logical-AND, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
all(int[], NDMaskedArray, bool)
The owner's kept int[] form of all(NDAxis?, NDMaskedArray, bool).
public NDMaskedArray all(int[] axis, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked logical-AND, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
all(NDAxis?, NDMaskedArray, bool)
Logical-AND over the unmasked elements (masked slots read True) — NumPy's MaskedArray.all(axis=None, out=None, keepdims).
public NDMaskedArray all(NDAxis? axis = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked logical-AND, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
anom(int?, DType)
Anomalies (deviations from the mean along the axis).
public NDMaskedArray anom(int? axis = null, DType dtype = null)
Parameters
Returns
- NDMaskedArray
Masked anomalies.
any(int, NDMaskedArray, bool)
The owner's kept int form of any(NDAxis?, NDMaskedArray, bool).
public NDMaskedArray any(int axis, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked logical-OR, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
any(int[], NDMaskedArray, bool)
The owner's kept int[] form of any(NDAxis?, NDMaskedArray, bool).
public NDMaskedArray any(int[] axis, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked logical-OR, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
any(NDAxis?, NDMaskedArray, bool)
Logical-OR over the unmasked elements (masked slots read False) — NumPy's MaskedArray.any(axis=None, out=None, keepdims).
public NDMaskedArray any(NDAxis? axis = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked logical-OR, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
argmax(int?, object, NDArray, bool)
Indices of the maximum (masked slots ignored) — NumPy's MaskedArray.argmax(axis=None, fill_value=None,
out=None, *, keepdims=False).
public NDArray argmax(int? axis = null, object fill_value = null, NDArray @out = null, bool keepdims = false)
Parameters
axisint?Axis or null.
fill_valueobjectMasked fill override.
outNDArrayWhere to write the indices (returned); np.argmax's checks.
keepdimsboolKeep the reduced axis with length 1.
Returns
- NDArray
int64 index array, or
out.
Exceptions
- TypeError
out's dtype cannot hold int64 indices safely.- ValueError
outhas the wrong shape.
argmin(int?, object, NDArray, bool)
Indices of the minimum (masked slots ignored) — NumPy's MaskedArray.argmin(axis=None, fill_value=None,
out=None, *, keepdims=False).
public NDArray argmin(int? axis = null, object fill_value = null, NDArray @out = null, bool keepdims = false)
Parameters
axisint?Axis or null.
fill_valueobjectMasked fill override.
outNDArrayWhere to write the indices (returned); np.argmin's checks.
keepdimsboolKeep the reduced axis with length 1.
Returns
- NDArray
int64 index array, or
out.
Exceptions
- TypeError
out's dtype cannot hold int64 indices safely.- ValueError
outhas the wrong shape.
argpartition(int, int?, string, string)
Returns the indices that would partition the DATA around the kth-th element
(NumPy's MaskedArray.argpartition). FOOTGUN — this IGNORES the mask exactly as
partition(int, int?, string, string) does (NumPy warns and delegates to
ndarray.argpartition): the index permutation is computed from the raw data, and the result
carries a COPY of THIS array's mask UNMOVED (positionally; flattened with axis null), so a
masked input position shows as masked in the result even though the result holds indices, not values.
Reproduced for parity; prefer argsort(int?, string, object, bool, object, bool, bool).
public NDMaskedArray argpartition(int kth, int? axis = -1, string kind = "introselect", string order = null)
Parameters
kthintIndex whose element lands in final sorted position; negatives count from the end.
axisint?Axis to partition along; null flattens first. Default last axis.
kindstringSelection algorithm — only "introselect".
orderstringField order (unused).
Returns
- NDMaskedArray
A masked array of int64 indices, built as NumPy's
array_finalizebuilds the subclass result: a copy of this array's mask in its original positions, this array's hard-mask flag, and its stored fill converted to int64 (7.5 reads back long 7).
Remarks
Until 2026-10-08 the result shared this array's mask (a mask write through it reached this array) and
its fill object unconverted, came back soft, and kept the mask's N-D shape under axis null.
argsort(bool, object, string, object, bool, bool)
Indices that would sort the array with masked entries at the end (or front), with NumPy's DEFAULT axis
(MaskedArray.argsort(axis=np._NoValue, kind=None, order=None, endwith=True, fill_value=None, *,
stable=False): the last axis of a 0-d / 1-D array, the FLATTENED array — NumPy's deprecated default — from
two dimensions on).
public NDArray argsort(bool endwith = true, object fill_value = null, string kind = null, object order = null, bool stable = false, bool descending = false)
Parameters
endwithboolTrue (default) sorts masked LAST; false sorts them FIRST.
fill_valueobjectOverride the masked sort key; null uses the endwith default.
kindstringNumPy's sort kind, or null for the default (validated with NumPy's text).
orderobjectNumPy's structured-array field order (refused for numeric data).
stableboolNumPy's keyword-only
stable: true is NumPy'sValueError:(the method's first statement).stableparameter is not supported for masked arrays.descendingboolNumPy 2.5's keyword-only
descending: true is NumPy'sValueError:(the method's second statement).descendingparameter is not supported for masked arrays.
Returns
Remarks
C#'s spelling of NumPy's axis=<no value>: endwith stays first so a
positional null still means axis=None (see argsort(int?, string, object, bool, object, bool, bool));
name the API-parity batch 9 keywords (m.argsort(kind: "stable", endwith: false)).
Exceptions
- ValueError
stableordescendingtrue (stable first), an unknownkind, or anorder.
argsort(int?, string, object, bool, object, bool, bool)
Indices that would sort the array along axis with masked entries at the end (or
front) — NumPy's MaskedArray.argsort(axis, kind=None, order=None, endwith=True, fill_value=None, *,
stable=False).
public NDArray argsort(int? axis, string kind = null, object order = null, bool endwith = true, object fill_value = null, bool stable = false, bool descending = false)
Parameters
axisint?Sort axis (negative counts from the end), or null for the flattened array.
kindstringNumPy's sort kind, or null for the default (validated with NumPy's text). Added in API-parity batch 9, in NumPy's second slot, where C# had
endwith.orderobjectNumPy's structured-array field order (refused for numeric data).
endwithboolTrue (default) sorts masked LAST; false sorts them FIRST.
fill_valueobjectOverride the masked sort key; null uses the endwith default.
stableboolNumPy's keyword-only
stable: true is NumPy'sValueError:stableparameter is not supported for masked arrays.descendingboolNumPy 2.5's keyword-only
descending: true is NumPy'sValueError:, checked afterdescendingparameter is not supported for masked arrays.stable.
Returns
Exceptions
- AxisError
axisis outside the array.- ValueError
stableordescendingtrue (stable first), an unknownkind, or anorder.
astype(DType, char, string, bool)
Casts the DATA to dtype, PRESERVING the mask (NumPy's MaskedArray.astype, which is
ndarray's astype(dtype, order='K', casting='unsafe', copy=True) plus the subclass's
array_finalize). Returns a NDMaskedArray, unlike the underlying
astype(DType, char, string, bool).
public NDMaskedArray astype(DType dtype, char order = 'K', string casting = "unsafe", bool copy = true)
Parameters
dtypeDTypeTarget element dtype.
ordercharThe data's layout:
'C','F','A'or'K'(ndarray.astype's). The new mask is laid out like the new data (C when it is C-contiguous, F when F-contiguous, else K), asarray_finalizecasts it.castingstringndarray.astype's casting rule name, checked before anything is allocated.
copyboolCopy the data even when the dtype and the layout already match (NumPy default true); false returns this array itself when nothing has to change.
Returns
- NDMaskedArray
A masked array of the new dtype with the same mask, or this array.
Remarks
NumPy's array_finalize runs _update_from, which since NumPy 2.5.3 / 2.5.4 converts a stored fill
of another dtype with the conversion's errors caught (CheckFillValueOrDefault(NDArray, DType)):
the result stores a converted COPY, or NOTHING when the conversion fails, and then reads its own default. A fill
of 7.5 reads back long 7 after astype(int64); a text fill follows a width change
('qrs' becomes 'q' after astype('U1'), b'qr' after astype('S2')) and a number
fill becomes its str() after a text cast. A fill that was never set or read is not stored, so the result
reads ITS OWN default — and a default that was READ but does not convert is dropped the same way: the float64
default 1e20 into int64 / int8 (an FE_INVALID cast, which NumPy runs under errstate(invalid='raise'))
and a text array's read default 'N/A' into float64 both leave the result reading its own default, where
NumPy 2.4 stored long.MinValue / 0 and raised Cannot convert fill_value N/A to dtype float64.
Order. ndarray.astype allocates the result (PyArray_NewLikeArray, whose
__array_finalize__ converts the fill) BEFORE it copies the data into it; since the conversion no longer
raises, a text array whose data does not parse reports the data's ValueError (probed: ['ab', '1'] with
fill 'zz' into float64 is could not convert string to float). The result's mask is a COPY of this
array's and its hard-mask flag is this array's; with copy false, a layout the order accepts
and an equivalent dtype the array itself is returned (no new array, so no fill conversion).
One signature in NumPy's keyword order (API-parity batch 3, 2026-11-11; was astype(dtype, copy)):
a positional copy is written copy: false.
Exceptions
- ValueError
An unknown
orderorcastingname (NumPy's argument parse, before anything else).- InvalidCastException
The cast is not allowed under
casting(checked before the fill conversion, as array_astype checks it before it allocates the result; NumPy's TypeError).- ValueError
A text element of the data that does not parse into a numeric
dtype(could not convert string to float: np.str_('ab')).- OverflowError
An integer text of the data outside an integer
dtype.- UnicodeError
A text cast between the string classes that cannot encode or decode a character.
byteswap(bool)
Returns the array with each data element's bytes reversed (NumPy's MaskedArray.byteswap, which is
ndarray.byteswap: the mask's VALUES ride through unchanged, a byteswap being a pure data
reinterpretation). With inplace the existing data buffer is swapped and THIS instance is
returned; otherwise a fresh masked array over swapped data is returned.
public NDMaskedArray byteswap(bool inplace = false)
Parameters
inplaceboolSwap the data buffer in place and return this instance (true), or return a new masked array over a swapped copy (false, the default).
Returns
- NDMaskedArray
This instance when
inplace, else a new NDMaskedArray over the swapped copy, built as NumPy'sarray_finalizebuilds it: a COPY of this array's mask, this array's hard-mask flag, and a converted copy of its stored fill (never the shared objects: a write to either array's mask or fill leaves the other's alone).
Remarks
Until 2026-10-08 the copy shared this array's mask (a mask write through it reached this array) and its fill object, and came back soft.
choose(object[], NDMaskedArray, string)
Uses THIS array's elements as indices to select from choices — NumPy's
MaskedArray.choose(choices, out=None, mode='raise'), which is ndarray.choose: the STORED index
values (a masked slot's too) select from the choices' raw data, and the result carries a copy of this array's
mask (the choices' masks are not read), its fill value and its hard-mask flag. Use the module
choose(object, object[], NDMaskedArray, string) for the mask-aware merge.
public NDMaskedArray choose(object[] choices, NDMaskedArray @out = null, string mode = "raise")
Parameters
choicesobject[]The choice arrays (an NDArray[] binds via covariance; scalars need
new object[]{…}).outNDMaskedArrayWhere to write the chosen data (returned); its mask is left as it is, as in NumPy.
modestringOut-of-bounds index policy: "raise" (default)/"wrap"/"clip"; it follows
out, as in NumPy.
Returns
- NDMaskedArray
The selected, masked array, or
out.
Remarks
Until API-parity batch 8 this ran the module form (masks of the choices included, a masked index read as 0); NumPy's method never did.
Exceptions
- ValueError
A stored index value is out of range under
mode="raise".- TypeError
out's shape is not the result's.
clip(object, object, NDMaskedArray, DType)
Clamps each element into [min, max] — NumPy's MaskedArray.clip(min=None, max=None, out=None,
**kwargs), which is ndarray.clip: the clip ufunc over this array, so the result is masked wherever
this array or a masked bound is.
public NDMaskedArray clip(object min = null, object max = null, NDMaskedArray @out = null, DType dtype = null)
Parameters
minobjectLower bound (array-like / scalar / masked array), or null (NumPy's None, the default) for no lower clip.
maxobjectUpper bound, or null (the default) for no upper clip; with both null the result is a copy, as NumPy's
m.clip().outNDMaskedArrayNumPy's
out: the clipped data is written into it and the out ITSELF is returned (the method has no module-level view); a masked out's mask is replaced by the operands' (hard or not). An NDArray converts (NumPy's plain out). Added in API-parity batch 9.dtypeDTypeNumPy's ufunc
dtypekeyword: the dtype the clip computes in. Added in API-parity batch 9.
Returns
- NDMaskedArray
The clamped masked array (this array's fill value and hardness), or
out.
Remarks
NumPy 2.x's keywords since 2026-11-11 (were a_min / a_max, which NumPy's method refuses);
the module function clip(object, object, object, NDMaskedArray, object, object, object, bool?, DType)
keeps NumPy's a_min / a_max and returns a VIEW of an out.
Exceptions
- OverflowError
A C# integer bound that does not fit this array's integer dtype.
- UFuncTypeError
The clip refuses
dtypeor the out's dtype.- ValueError
A bound or the out does not broadcast.
compress(object, int?, NDMaskedArray)
Keep only elements where the flattened condition is True — NumPy's
MaskedArray.compress(condition, axis=None, out=None); mask carried alike.
public NDMaskedArray compress(object condition, int? axis = null, NDMaskedArray @out = null)
Parameters
conditionobjectBoolean array-like selector over the (flattened) elements.
axisint?Axis to compress along, or null to flatten first.
outNDMaskedArrayWhere to write the compressed DATA; its mask is never touched, and the result is a new masked array over it (see compress(object, object, int?, NDMaskedArray)).
Returns
- NDMaskedArray
The compressed masked array.
Exceptions
- ArgumentException
The condition is not 1-D.
- IndexError
A truthy condition entry past the axis length.
- ValueError
out's shape is not the result's.
compressed()
The 1-D array of the UNMASKED values in C-order (NumPy's MaskedArray.compressed) —
a plain NDArray, since a compressed result has no mask.
public NDArray compressed()
Returns
conj()
Complex conjugate (real data passes through); mask preserved (NumPy's conj).
public NDMaskedArray conj()
Returns
- NDMaskedArray
A masked array of conj(data).
conjugate()
Alias of conj() (NumPy's conjugate).
public NDMaskedArray conjugate()
Returns
- NDMaskedArray
A masked array of conj(data).
copy(char)
A DEEP copy of this masked array — data AND mask duplicated, sharing no memory with the source
(NumPy's MaskedArray.copy). Reach for it before mutating a view/slice you must not disturb.
public NDMaskedArray copy(char order = 'C')
Parameters
ordercharThe copy's layout, NumPy's
MaskedArray.copy(order='C'):'C'(the default),'F','A'or'K'— data and mask alike (API-parity batch 7).
Returns
- NDMaskedArray
An independent NDMaskedArray with the same values, mask and fill value.
Exceptions
- ValueError
An order letter NumPy does not have.
count(int, bool)
The owner's kept int form of count(NDAxis?, bool).
public NDArray count(int axis, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDArray
The int64 count of the unmasked elements (a plain array, never masked).
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis.
count(int[], bool)
The owner's kept int[] form of count(NDAxis?, bool).
public NDArray count(int[] axis, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDArray
The int64 count of the unmasked elements (a plain array, never masked).
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis.
count(NDAxis?, bool)
Count of the unmasked elements — NumPy's MaskedArray.count(axis=None, keepdims).
public NDArray count(NDAxis? axis = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.keepdimsboolKeep the reduced axes with length 1.
Returns
- NDArray
The int64 count of the unmasked elements (a plain array, never masked).
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis.
cumprod(int?, DType, NDMaskedArray)
Cumulative product (masked positions preserved) — NumPy's MaskedArray.cumprod(axis=None, dtype=None,
out=None).
public NDMaskedArray cumprod(int? axis = null, DType dtype = null, NDMaskedArray @out = null)
Parameters
axisint?Axis or null.
dtypeDTypeAccumulator dtype.
outNDMaskedArrayWhere to write the scan (returned); see cumprod(object, int?, DType, NDMaskedArray).
Returns
- NDMaskedArray
Masked cumulative product, or
out.
Exceptions
- IncorrectShapeException
outhas the wrong shape, or a hard masked out this array's mask does not broadcast to.- AxisError
axisis out of range.- TypeError
Text data: the scan has no string loop.
cumsum(int?, DType, NDMaskedArray)
Cumulative sum (masked positions preserved) — NumPy's MaskedArray.cumsum(axis=None, dtype=None,
out=None).
public NDMaskedArray cumsum(int? axis = null, DType dtype = null, NDMaskedArray @out = null)
Parameters
axisint?Axis or null.
dtypeDTypeAccumulator dtype.
outNDMaskedArrayWhere to write the scan (returned); a masked out takes this array's mask through
setmask, a plain one the data only (see cumsum(object, int?, DType, NDMaskedArray)).
Returns
- NDMaskedArray
Masked cumulative sum, or
out.
Exceptions
- IncorrectShapeException
outhas the wrong shape, or a hard masked out this array's mask does not broadcast to.- AxisError
axisis out of range.- TypeError
Text data: the scan has no string loop.
diagonal(int, int, int)
Extracts the offset-th diagonal (mask alike); NumPy's MaskedArray.diagonal.
public NDMaskedArray diagonal(int offset = 0, int axis1 = 0, int axis2 = 1)
Parameters
Returns
- NDMaskedArray
The masked diagonal.
dot(object, NDMaskedArray, bool)
Dot product with masked slots treated as 0 — NumPy's MaskedArray.dot(b, out=None, strict=False);
with strict the mask is propagated along the contracted axes first (see
dot(object, object, bool, NDMaskedArray)).
public NDMaskedArray dot(object b, NDMaskedArray @out = null, bool strict = false)
Parameters
bobjectRight operand.
outNDMaskedArrayA MASKED array to write the product and its mask into (returned); see the module form for its rules. It precedes
strict, as in NumPy's method (the module puts strict first), so a positional strict is now writtenstrict: true.strictboolPropagate masks along the contracted axes before the product (default false).
Returns
- NDMaskedArray
The masked dot product, or
out.
Exceptions
- AttributeError
outis a plain array ('numpy.ndarray' object has no attribute '_data').- ValueError
outis not C-contiguous, has another dtype than the product's, or another shape (np.dot's texts).- TypeError
A 0-d
outwithout a mask ('out' must be an array), raised after its data was written.- IncorrectShapeException
The operands' shapes are not aligned.
fill(object)
Overwrites EVERY data slot with value in place and leaves the mask untouched
(NumPy's MaskedArray.fill). A masked slot therefore still reads as masked while its
hidden data becomes value — fill is a data operation, NOT an unmask, so
it does not clear the mask (unlike an indexer assignment on a soft mask). The mask's hardness is
irrelevant here (it never gates the data buffer).
public void fill(object value)
Parameters
valueobjectThe scalar written into every data element; cast to the data dtype like NumPy.
Exceptions
- InvalidOperationException
The underlying data buffer is not writeable (e.g. a broadcast view), surfaced by the base fill(object).
filled(object)
The data with every masked element replaced by fill_value (NumPy's
MaskedArray.filled): the standard way to hand masked data to code that cannot see the mask — the mask
is "baked in" as a sentinel value while the dtype is preserved. When there is nothing to substitute (no mask,
or no slot masked) the result is a VIEW of the data, as NumPy's return self._data is.
public NDArray filled(object fill_value = null)
Parameters
fill_valueobjectThe value written at masked positions; null uses this array's fill_value (whose getter materializes the default, as NumPy's does: for int8 data the int64 999999, which the copy casts to 63). An explicit value first goes through NumPy's
_check_fill_value(CheckFillValue(object, DType): converted to the data dtype,300on int8 refused, 2.5 on int8 stored as 2). A text fill is truncated to the data's width ('N/A'into<U2is'N/').
Returns
- NDArray
A K-order copy of the data with the masked slots filled; or, when no slot is masked, a new VIEW of the data (writes through it reach this array; disposing it releases only the view's own reference).
Remarks
NumPy's order: if m is nomask: return self._data; resolve the fill (self.fill_value or
_check_fill_value(fill_value, self.dtype)); elif not m.any(): return self._data; else
result = self._data.copy('K'); np.copyto(result, fill_value, where=m). So an unmasked array never
refuses (or converts) the argument, and a fill that NumPy refuses is refused even when no slot is masked —
except a NUMBER for TEXT data: NumPy formats it (which cannot fail) and then returns the data untouched when
nothing is masked, so that case answers here without formatting it.
Scoped ([NDScoped]): the 0-d fill scalar handed to copyto(NDArray, NDArray, string, NDArray) (and a converted array
fill) is reclaimed on return; only the result leaves.
Exceptions
- TypeError
See CheckFillValue(object, DType): a string
fill_valuefor a numeric array, a number the data dtype cannot hold (Cannot convert fill_value 300 to dtype int8), a complex for a real dtype, or a text fill the data's class cannot encode or decode.- AttributeError
No
fill_valueon the masked singleton: its getter cannot materialize a default (NumPy'sattributes of masked are not writeable).- NotSupportedException
The stored fill cannot reach the data under NumPy's
same_kindrule: NumPy'snp.copytoraises and NumPy then returns an OBJECT array (np.chooseover the data as objects), a dtype NumSharp lacks. Since NumPy 2.5.4 a derived array never inherits such a fill (_update_fromconverts a fill across a dtype change, or drops it:ma.absoluteof a complex array stores the float 1.0 where NumPy 2.4 shared the complex fill), and a given fill is converted first, so only a stale stored fill reaches this — in NumPy through the deprecateddtypesetter, which NumSharp does not have.
flatten(char)
Flattened COPY (NumPy's flatten — always copies, unlike ravel(char)).
public NDMaskedArray flatten(char order = 'C')
Parameters
orderchar'C' (default) or 'F'.
Returns
- NDMaskedArray
The flattened masked copy.
getfield(DType, int)
NumPy's MaskedArray.getfield(dtype, offset=0): a masked VIEW of a field of each element - the data
reinterpreted as dtype at offset bytes (getfield(DType, int)),
carrying this array's mask (shared: a masked write through either array reaches the other), hard-mask flag
and a copy of its stored fill value, as NumPy's array_finalize carries them onto any view.
public NDMaskedArray getfield(DType dtype, int offset = 0)
Parameters
dtypeDTypeThe field's dtype; null is NumPy's default float64.
offsetintThe field's byte offset within an element (not negative).
Returns
- NDMaskedArray
A masked array over the field view, of this array's shape.
Remarks
The stored fill is copied at THIS array's dtype and read back at the field's (a float64 fill 7.0 reads
np.float32(7.0) on a float32 field, as NumPy's getter converts it); setting the field's fill leaves this
array's alone. Scoped by hand: the field view is built before the mask is attached, and handed back through
Yield(NDScope, NDMaskedArray). API-parity batch 12.
Exceptions
- ValueError
getfield(DType, int)'s refusals: a negative offset (
offset is negative), a field past the element (new type plus offset is larger than original type).- TypeError
getfield(DType, int)'s
Cannot get/set field of an object array.- NotSupportedException
getfield(DType, int)'s refusal of a non-native field descriptor.
harden_mask()
Makes the mask HARD (NumPy's harden_mask): from now on a plain-value assignment cannot
unmask a slot — only currently-unmasked positions change. Mutates and returns THIS array.
public NDMaskedArray harden_mask()
Returns
- NDMaskedArray
This masked array (now hard-masked).
Remarks
Only THIS instance changes. A slice taken earlier copied the flag when it was created (see UpdateFrom(NDMaskedArray)), so it stays soft, and a write through it can still unmask this array's slots, exactly as in NumPy. Harden first, then slice.
ids()
The addresses of the data and mask buffers (NumPy's MaskedArray.ids); the mask address
is 0 when there is no mask (NumPy returns id(nomask) there — an arbitrary sentinel either way).
public (long data, long mask) ids()
Returns
iscontiguous()
Whether the data is C-contiguous (NumPy's MaskedArray.iscontiguous — the CONTIGUOUS
flag), an O(1) flag read.
public bool iscontiguous()
Returns
- bool
True iff the data laid out row-major-contiguous.
item(params long[])
One element as a boxed scalar — NumPy's MaskedArray.item(*args), which IS ndarray.item: it
reads the DATA and ignores the mask, so a masked element returns its STORED value (never
NDMasked).
public object item(params long[] args)
Parameters
argslong[]NumPy's
*args: nothing (the array must hold exactly one element), one flat C-order index (negative counts from the end), or one index per dimension.
Returns
- object
The element's value, boxed in its C# type (a
longfor int64 data, adoublefor float64, …).
Remarks
Forwards to item() / item(long) / item(params long[]) over the data, so its argument checks are ndarray's. Until API-parity batch 8 this took no argument and answered a masked element with the masked constant; NumPy's never did.
Exceptions
- ValueError
No argument and the array does not hold exactly one element (
can only convert an array of size 1 to a Python scalar), or neither one index nor one per dimension (incorrect number of indices for array): NumPy's ValueErrors since API-parity batch 13 (parity QA-04).- IndexOutOfRangeException
A flat index out of bounds (NumPy's IndexError text
index 9 is out of bounds for size 6), or a coordinate out of its axis' bounds.
max(int, NDMaskedArray, object, bool)
The owner's kept int form of max(NDAxis?, NDMaskedArray, object, bool).
public NDMaskedArray max(int axis, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe value the masked slots take before the reduction, or null for maximum_fill_value.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked maximum, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
max(int[], NDMaskedArray, object, bool)
The owner's kept int[] form of max(NDAxis?, NDMaskedArray, object, bool).
public NDMaskedArray max(int[] axis, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe value the masked slots take before the reduction, or null for maximum_fill_value.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked maximum, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
max(NDAxis?, NDMaskedArray, object, bool)
Maximum over the unmasked elements — NumPy's MaskedArray.max(axis=None, out=None, fill_value=None, keepdims).
public NDMaskedArray max(NDAxis? axis = null, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe value the masked slots take before the reduction, or null for maximum_fill_value.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked maximum, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
mean(int, DType, NDMaskedArray, bool)
The owner's kept int form of mean(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray mean(int axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked mean, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
mean(int[], DType, NDMaskedArray, bool)
The owner's kept int[] form of mean(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray mean(int[] axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked mean, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
mean(NDAxis?, DType, NDMaskedArray, bool)
Mean over the unmasked elements — NumPy's MaskedArray.mean(axis=None, dtype=None, out=None, keepdims).
public NDMaskedArray mean(NDAxis? axis = null, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked mean, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
min(int, NDMaskedArray, object, bool)
The owner's kept int form of min(NDAxis?, NDMaskedArray, object, bool).
public NDMaskedArray min(int axis, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe value the masked slots take before the reduction, or null for minimum_fill_value.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked minimum, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
min(int[], NDMaskedArray, object, bool)
The owner's kept int[] form of min(NDAxis?, NDMaskedArray, object, bool).
public NDMaskedArray min(int[] axis, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe value the masked slots take before the reduction, or null for minimum_fill_value.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked minimum, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
min(NDAxis?, NDMaskedArray, object, bool)
Minimum over the unmasked elements — NumPy's MaskedArray.min(axis=None, out=None, fill_value=None, keepdims).
public NDMaskedArray min(NDAxis? axis = null, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe value the masked slots take before the reduction, or null for minimum_fill_value.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked minimum, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
nonzero()
Indices of the non-zero UNMASKED elements (NumPy's MaskedArray.nonzero) — one plain
int64 index array per dimension; masked slots are treated as zero and excluded.
public NDArray<long>[] nonzero()
Returns
partition(int, int?, string, string)
Partitions the DATA in place around the kth-th element (NumPy's
MaskedArray.partition). FOOTGUN — this IGNORES the mask: NumPy itself emits a
UserWarning here and delegates to ndarray.partition, which reorders only the data
while the mask array stays in its ORIGINAL positions — so after partitioning the mask no longer
lines up with the values it marked. NumSharp reproduces that behavior (there is no warning channel).
Prefer sort(int,bool,object), which moves the mask with the data.
public void partition(int kth, int? axis = -1, string kind = "introselect", string order = null)
Parameters
kthintIndex (or, in the sibling overload, indices) whose element(s) land in final sorted position; negatives count from the end.
axisint?Axis to partition along; null flattens first. Default last axis.
kindstringSelection algorithm — only "introselect".
orderstringField order (structured dtypes only; unused here).
partition(int[], int?, string, string)
Multi-kth overload of partition(int, int?, string, string) —
same mask-oblivious footgun; each listed element lands in final sorted position.
public void partition(int[] kth, int? axis = -1, string kind = "introselect", string order = null)
Parameters
kthint[]Indices whose elements land in final sorted position.
axisint?Axis to partition along; null flattens first.
kindstringSelection algorithm — only "introselect".
orderstringField order (unused).
prod(int, DType, NDMaskedArray, bool)
The owner's kept int form of prod(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray prod(int axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked product, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
prod(int[], DType, NDMaskedArray, bool)
The owner's kept int[] form of prod(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray prod(int[] axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked product, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
prod(NDAxis?, DType, NDMaskedArray, bool)
Product over the unmasked elements — NumPy's MaskedArray.prod(axis=None, dtype=None, out=None, keepdims).
public NDMaskedArray prod(NDAxis? axis = null, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked product, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
product(int, DType, NDMaskedArray, bool)
The owner's kept int form of product(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray product(int axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked product, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
product(int[], DType, NDMaskedArray, bool)
The owner's kept int[] form of product(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray product(int[] axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked product, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
product(NDAxis?, DType, NDMaskedArray, bool)
Alias of prod (NumPy's MaskedArray.product): the product of the unmasked elements.
public NDMaskedArray product(NDAxis? axis = null, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked product, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
ptp(int, NDMaskedArray, object, bool)
The owner's kept int form of ptp(NDAxis?, NDMaskedArray, object, bool).
public NDMaskedArray ptp(int axis, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe fill passed to both max and min, or null for their defaults.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked range (max − min), or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
ptp(int[], NDMaskedArray, object, bool)
The owner's kept int[] form of ptp(NDAxis?, NDMaskedArray, object, bool).
public NDMaskedArray ptp(int[] axis, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe fill passed to both max and min, or null for their defaults.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked range (max − min), or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
ptp(NDAxis?, NDMaskedArray, object, bool)
Peak-to-peak (max − min) over the unmasked elements — NumPy's MaskedArray.ptp(axis=None, out=None, fill_value=None, keepdims=False).
public NDMaskedArray ptp(NDAxis? axis = null, NDMaskedArray @out = null, object fill_value = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).fill_valueobjectThe fill passed to both max and min, or null for their defaults.
keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked range (max − min), or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- MaskError
A plain integer or bool
out(NumPy'sMasked data information would be lost in one or more location.).- TypeError
A StringDType operand (no extremum fill).
put(NDArray, object, string)
Sets x.flat[indices] = values (mask-aware) — NumPy's MaskedArray.put, the instance form of
put(object, NDArray, object, string): masked values mask the slots, plain values unmask them, and
under a hard mask NumPy's statements drop the indices on masked slots first (an N-D target then always raises
IndexError, short values are zero-padded rather than cycled; see put(object, NDArray, object, string)).
public void put(NDArray indices, object values, string mode = "raise")
Parameters
indicesNDArrayFlat integer indices.
valuesobjectScalar/array/masked values.
modestringOut-of-bounds policy: "raise" (default)/"wrap"/"clip".
Exceptions
putmask(object, object)
IN-PLACE conditional write (the instance form of putmask(object, object, object)):
writes values where mask is True and reconciles the mask there
(masked values mask the slots, plain values unmask them).
public void putmask(object mask, object values)
Parameters
maskobjectBoolean array-like selecting the write positions.
valuesobjectScalar/array/NDMaskedArray supplying the data (and, if masked, the mask).
ravel(char)
Flattened VIEW in row-major order (NumPy's ravel); mask flattened alike.
public NDMaskedArray ravel(char order = 'C')
Parameters
orderchar'C' (row-major, default) or 'F' (column-major).
Returns
- NDMaskedArray
The flattened masked array.
repeat(int, int?)
Repeat elements (mask repeated alike, so repeated masked entries stay masked).
public NDMaskedArray repeat(int repeats, int? axis = null)
Parameters
Returns
- NDMaskedArray
The masked array.
reshape(Shape, char, bool?)
Reshape, the mask reshaped alike — NumPy's MaskedArray.reshape(shape, /, *, order='C',
copy=None): the data's and the mask's reshape with the same keywords, then
result._update_from(self).
public NDMaskedArray reshape(Shape shape, char order = 'C', bool? copy = null)
Parameters
shapeShapeThe new dimensions: a tuple, an int, an
int[]/long[]or a NumSharp.NDMaskedArray.Shape (one entry may be -1).ordercharThe index order:
'C'(the default),'F'or'A';'K'is refused.copybool?Null copies only when needed (NumPy's None); true always copies the data and the mask; false refuses a copy.
Returns
- NDMaskedArray
The reshaped masked array, with this array's fill value and hard-mask flag.
Remarks
Added in API-parity batch 8 (batch 7's ndarray reshape, over the data and the mask).
Exceptions
- IncorrectShapeException
The size does not match.
- ValueError
A bad
order, more than one unknown dimension, orcopyfalse when a copy is needed (Unable to avoid creating a copy while reshaping.).
reshape(params int[])
Reshape to loose dimensions, the mask reshaped alike — NumPy's MaskedArray.reshape(*s) form,
m.reshape(2, 3).
public NDMaskedArray reshape(params int[] shape)
Parameters
shapeint[]New dimensions (one may be -1).
Returns
- NDMaskedArray
The reshaped masked array (a view when the layout allows it), with this array's fill value and hard-mask flag.
Remarks
Kept beside reshape(Shape, char, bool?), NumPy's keyword form: a C# integer list binds here (an identity conversion beats the user-defined one to NumSharp.NDMaskedArray.Shape).
Exceptions
- IncorrectShapeException
The size does not match.
- ValueError
More than one unknown dimension.
resize(Shape, bool, bool)
NOT SUPPORTED in place — raises exactly as NumPy's MaskedArray.resize does: a masked array
does not own its data, so it cannot be resized in place. Use the module function
resize(object, Shape) (which returns a NEW tiled masked array).
public void resize(Shape newshape, bool refcheck = true, bool order = false)
Parameters
newshapeShapeIgnored (NumPy's target shape, keyword
newshape).refcheckboolIgnored (NumPy's reference-count check flag).
orderboolIgnored (NumPy's
order=False, which NumPy's own source calls broken).
Exceptions
- ValueError
Always, NumPy's type and verbatim text (since 2026-11-11; NumSharp raised NotSupportedException with the same text before it had Python's exception classes).
round(int, NDMaskedArray)
Rounds each element to decimals places (half-to-even), preserving the mask — NumPy's
MaskedArray.round(decimals=0, out=None).
public NDMaskedArray round(int decimals = 0, NDMaskedArray @out = null)
Parameters
decimalsintDecimal places (negative rounds to the left of the decimal point).
outNDMaskedArrayWhere to write the rounded data (returned). A MASKED out goes through NumPy's in-place multiply / rint / divide and their
array_wrap: an infinite result there is written as 1.0 (10**-decimalsfor negative decimals) — visible once this array's mask is set over it — and then takes this array's mask throughsetmask(a hard out also keeps the masked slots the wraps left). A plain out (converted) receives the rounded data only. See RoundMethodInto(NDMaskedArray, int, NDMaskedArray).
Returns
- NDMaskedArray
The masked, rounded array, or
out.
Exceptions
- AttributeError
Complex data into a masked
out(property 'real' of 'MaskedArray' object has no setter), before anything is written.- UFuncOutputCastingError
out's dtype cannot hold the rounded values (Cannot cast ufunc 'multiply' output from dtype('float64') to dtype('int64') with casting rule 'same_kind').- ValueError
outhas another size (invalid output shape).
searchsorted(NDArray, string, NDArray)
Finds the insertion indices that keep the (assumed-sorted) DATA sorted (NumPy's
MaskedArray.searchsorted, inherited from ndarray). It reads the raw data and IGNORES the
mask entirely — a masked entry is treated as its underlying value, so the caller is responsible
for masked slots not distorting the sorted order. Returns a PLAIN NDArray (integer
indices), never a masked array, matching NumPy.
public NDArray searchsorted(NDArray v, string side = "left", NDArray sorter = null)
Parameters
vNDArrayThe value(s) to insert.
sidestring"left" (first suitable index) or "right" (last), as in NumPy.
sorterNDArrayOptional integer index array giving a sort order for the data (an argsort result).
Returns
setfield(NDArray, DType, int)
NumPy's MaskedArray.setfield(val, dtype, offset=0): writes val into the field
getfield(dtype, offset) of every element - ndarray's setfield on the data, so masked slots are written
too (a hard mask included) and the mask is unchanged.
public void setfield(NDArray val, DType dtype, int offset = 0)
Parameters
valNDArrayThe value(s), broadcast to this array's shape and stored by NumPy's setitem (an unsafe cast: 1.5 into an int64 field stores 1, a text
"7"parses to 7). A C# number or string converts implicitly; a masked array's values go in as its data.dtypeDTypeThe field's dtype; null is NumPy's default float64.
offsetintThe field's byte offset within an element (not negative).
Remarks
API-parity batch 12: NumPy's MaskedArray inherits ndarray.setfield, which writes the data alone.
Exceptions
- ValueError
The data is read-only (
assignment destination is read-only); getfield(DType, int)'s dtype / offset refusals; a value that does not broadcast (could not broadcast input array from shape (2,) into shape (3,)).- TypeError
setfield(object, DType, int)'s refusals (None into an integer field, an object field).
- NotSupportedException
A non-native field descriptor.
shrink_mask()
Drops an all-False mask back to nomask IN PLACE (NumPy's MaskedArray.shrink_mask:
self._mask = _shrink_mask(self._mask); return self); a mask with a masked slot is kept.
public NDMaskedArray shrink_mask()
Returns
- NDMaskedArray
This array.
soften_mask()
Makes the mask SOFT again (NumPy's soften_mask, the default): a plain-value assignment
unmasks the assigned slots. Mutates and returns THIS array.
public NDMaskedArray soften_mask()
Returns
- NDMaskedArray
This masked array (now soft-masked).
Remarks
Only THIS instance changes: softening a slice leaves its parent hard (and the reverse), as in NumPy, where each array keeps its own copy of the flag.
sort(int, string, object, bool, object, bool, bool)
Sorts along an axis with masked entries pushed to the end (or front) and re-masked there — NumPy's
MaskedArray.sort(axis=-1, kind=None, order=None, endwith=True, fill_value=None, *, stable=False). Unlike
NumPy's method, which sorts in place and returns None, this returns the sorted copy
sort(object, int?, string, object, bool, object, bool?, bool?) builds and leaves this array as it is.
public NDMaskedArray sort(int axis = -1, string kind = null, object order = null, bool endwith = true, object fill_value = null, bool stable = false, bool descending = false)
Parameters
axisintSort axis (default last).
kindstringNumPy's sort kind, or null for the default (validated with NumPy's text). Added in API-parity batch 9, in NumPy's second slot, where C# had
endwith.orderobjectNumPy's structured-array field order; numeric data has no fields, so any value is NumPy's
ValueError: Cannot specify order when the array has no fields.endwithboolTrue (default) pushes masked to the END; false pushes them to the FRONT.
fill_valueobjectOverride the masked sort key; null uses the endwith default.
stableboolNumPy's keyword-only
stable: true is NumPy'sValueError:stableparameter is not supported for masked arrays.descendingboolNumPy 2.5's keyword-only
descending: true is NumPy'sValueError:, checked afterdescendingparameter is not supported for masked arrays.stable.
Returns
- NDMaskedArray
The sorted masked array.
Exceptions
- AxisError
axisis outside the array.- ValueError
stableordescendingtrue (stable first), an unknownkind, or anorder.
squeeze(int)
Remove ONE size-1 axis — the owner's kept int form beside squeeze(NDAxis?).
public NDMaskedArray squeeze(int axis)
Parameters
axisintThe size-1 axis to drop.
Returns
- NDMaskedArray
The squeezed masked array.
Exceptions
- ValueError
The axis' length is not 1.
- AxisError
The axis is out of range.
squeeze(int[])
Remove the listed size-1 axes — the owner's kept int[] form beside squeeze(NDAxis?); a null array is NumPy's None.
public NDMaskedArray squeeze(int[] axis)
Parameters
axisint[]The size-1 axes to drop, or null for all.
Returns
- NDMaskedArray
The squeezed masked array.
Exceptions
- ValueError
An axis' length is not 1, or an axis repeats.
- AxisError
An axis is out of range.
squeeze(NDAxis?)
Remove size-1 axes, the mask squeezed alike — NumPy's MaskedArray.squeeze(axis=None).
public NDMaskedArray squeeze(NDAxis? axis = null)
Parameters
axisNDAxis?The size-1 axis or axes to drop (an int, a tuple, an
int[]), or null for every size-1 axis.
Returns
- NDMaskedArray
The squeezed masked array (a view), with this array's fill value and hard-mask flag.
Remarks
NumPy's tuple axis arrived in API-parity batch 8 (it was one int?).
Exceptions
- ValueError
An axis whose length is not 1, or a repeated axis.
- AxisError
An axis out of range.
std(int, DType, NDMaskedArray, int, bool, object)
The owner's kept int form of std(NDAxis?, DType, NDMaskedArray, int, bool, object).
public NDMaskedArray std(int axis, DType dtype = null, NDMaskedArray @out = null, int ddof = 0, bool keepdims = false, object mean = null)
Parameters
axisintThe one axis to reduce (negative counts from the end).
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).ddofintDelta degrees of freedom: the divisor is the count minus
ddof.keepdimsboolKeep the reduced axes with length 1.
meanobjectAccepted for NumPy's signature and IGNORED: NumPy's ma.std does not forward it to var.
Returns
- NDMaskedArray
The masked standard deviation, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- AttributeError
A 0-d result of a masked operand into a masked
out(NumPy's numpy scalar has nomask).- MaskError
A masked 0-d result into a plain integer or bool
out.
std(int[], DType, NDMaskedArray, int, bool, object)
The owner's kept int[] form of std(NDAxis?, DType, NDMaskedArray, int, bool, object).
public NDMaskedArray std(int[] axis, DType dtype = null, NDMaskedArray @out = null, int ddof = 0, bool keepdims = false, object mean = null)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).ddofintDelta degrees of freedom: the divisor is the count minus
ddof.keepdimsboolKeep the reduced axes with length 1.
meanobjectAccepted for NumPy's signature and IGNORED: NumPy's ma.std does not forward it to var.
Returns
- NDMaskedArray
The masked standard deviation, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- AttributeError
A 0-d result of a masked operand into a masked
out(NumPy's numpy scalar has nomask).- MaskError
A masked 0-d result into a plain integer or bool
out.
std(NDAxis?, DType, NDMaskedArray, int, bool, object)
Standard deviation over the unmasked elements — NumPy's MaskedArray.std(axis=None, dtype=None, out=None, ddof=0, keepdims, mean).
public NDMaskedArray std(NDAxis? axis = null, DType dtype = null, NDMaskedArray @out = null, int ddof = 0, bool keepdims = false, object mean = null)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).ddofintDelta degrees of freedom: the divisor is the count minus
ddof.keepdimsboolKeep the reduced axes with length 1.
meanobjectAccepted for NumPy's signature and IGNORED: NumPy's ma.std does not forward it to var.
Returns
- NDMaskedArray
The masked standard deviation, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- AttributeError
A 0-d result of a masked operand into a masked
out(NumPy's numpy scalar has nomask).- MaskError
A masked 0-d result into a plain integer or bool
out.
sum(int, DType, NDMaskedArray, bool)
The owner's kept int form of sum(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray sum(int axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisintThe one axis to reduce (negative counts from the end).
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked sum (the masked singleton for a fully masked 0-d result), or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
sum(int[], DType, NDMaskedArray, bool)
The owner's kept int[] form of sum(NDAxis?, DType, NDMaskedArray, bool).
public NDMaskedArray sum(int[] axis, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked sum (the masked singleton for a fully masked 0-d result), or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
sum(NDAxis?, DType, NDMaskedArray, bool)
Sum over the unmasked elements — NumPy's MaskedArray.sum(axis=None, dtype=None, out=None, keepdims).
public NDMaskedArray sum(NDAxis? axis = null, DType dtype = null, NDMaskedArray @out = null, bool keepdims = false)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).keepdimsboolKeep the reduced axes with length 1.
Returns
- NDMaskedArray
The masked sum (the masked singleton for a fully masked 0-d result), or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.
swapaxes(int, int)
Swap two axes (mask swapped alike).
public NDMaskedArray swapaxes(int axis1, int axis2)
Parameters
Returns
- NDMaskedArray
The masked array with swapped axes.
take(NDArray, int?, NDMaskedArray, string)
Gather elements by index (mask gathered alike, so a taken element keeps its masked-ness) — NumPy's
MaskedArray.take(indices, axis=None, out=None, mode='raise').
public NDMaskedArray take(NDArray indices, int? axis = null, NDMaskedArray @out = null, string mode = "raise")
Parameters
indicesNDArrayInteger index array.
axisint?Axis or null.
outNDMaskedArrayWhere to write the gathered data (a masked out also takes the gathered mask through
setmask); see take(object, NDArray, int?, NDMaskedArray, string).modestringOut-of-bounds policy: "raise" (default)/"wrap"/"clip"; it follows
out, as in NumPy.
Returns
- NDMaskedArray
The masked array,
out, or for a 0-d result NDMasked / an unmasked 0-d array.
Exceptions
- IndexError
An index is out of bounds under
mode="raise".- ValueError
out's shape is not the result's.- AxisError
axisis out of range.
to_device(string, object)
Array-API device transfer (NumPy's MaskedArray.to_device, inherited from ndarray): "cpu" returns
this same masked array, with no copy; any other device, or a stream, raises as
to_device(string, object) does.
public NDMaskedArray to_device(string device, object stream = null)
Parameters
devicestringThe target device; must be
"cpu".streamobjectAccepted for the Array-API signature; must be null (NumSharp models no streams).
Returns
- NDMaskedArray
This masked array, unchanged.
Remarks
API-parity batch 12.
Exceptions
- ArgumentNullException
deviceis null (NumPy's TypeError:to_device() argument 1 must be str, not None).- ValueError
A stream (
The stream argument in to_device() is not supported), or another device (Unsupported device: gpu. Only 'cpu' is accepted.), in that order.
tobytes(object, char)
Returns the raw bytes of the array (NumPy's MaskedArray.tobytes) — the array is
filled(object) FIRST, so masked slots carry the fill sentinel and the mask itself is
NOT encoded (as NumPy documents, shape/dtype/fill_value are all lost).
public byte[] tobytes(object fill_value = null, char order = 'C')
Parameters
fill_valueobjectSentinel written at masked positions before encoding; null uses this array's fill_value (the dtype default when unset).
ordercharByte order of the copy: 'C' (row-major, default), 'F' (column-major), 'A'/'K' (resolved via the C-contiguous filled copy, so they equal 'C' here — a masked-array nuance vs NumPy, which can keep 'F' for an F-contiguous source under 'A').
Returns
Exceptions
- ArgumentException
orderis not one of C/F/A/K.
tofile(string, string, string)
NOT IMPLEMENTED — raises exactly as NumPy's MaskedArray.tofile does. A masked array cannot
be written to a binary file without losing the mask, so NumPy declines; the parameters exist only
to mirror its signature. Use tobytes(object, char) (with a fill value) to serialize.
public void tofile(string fid, string sep = "", string format = "%s")
Parameters
fidstringIgnored (NumPy's file id).
sepstringIgnored (NumPy's separator).
formatstringIgnored (NumPy's format).
Exceptions
- NotImplementedError
Always — NumPy's
NotImplementedError, type and text.
tolist(object)
Returns the array as a nested list structure (NumPy's MaskedArray.tolist): a boxed scalar
for a 0-D array, otherwise a jagged object[] whose leaves are the boxed CLR element
values. Masked positions become fill_value, or null when it is null —
NumPy fills masked entries with None by default — so the result is the "data with holes"
view a non-NumSharp consumer wants.
public object tolist(object fill_value = null)
Parameters
fill_valueobjectValue substituted at masked positions; null ⇒
nullin the output (NumPy'sNone). When non-null the array is filled(object) first, so no nulls appear and the value is cast into the data dtype exactly as NumPy coerces it.
Returns
- object
The bare boxed scalar for a 0-D array, else a nested object[] (one level per dimension); leaves are boxed element values, or
null/fill_valuewhere masked.
trace(int, int, int, DType, NDArray)
Sum of the diagonal, treating masked slots as 0 — NumPy's MaskedArray.trace(offset=0, axis1=0, axis2=1,
dtype=None, out=None); a PLAIN array, float64 unless dtype is given (NumPy's
astype(None) quirk).
public NDArray trace(int offset = 0, int axis1 = 0, int axis2 = 1, DType dtype = null, NDArray @out = null)
Parameters
offsetintDiagonal offset.
axis1intFirst plane axis.
axis2intSecond plane axis.
dtypeDTypeResult dtype; null ⇒ float64.
outNDArrayWhere to write the trace: returned for a masked array; for an unmasked one the out is written and a float64 (or
dtype) COPY is returned (see trace(object, int, int, int, DType, NDArray)).
Returns
Exceptions
- ArgumentException
Fewer than two dimensions, or invalid axes.
- TypeError
Unmasked text data: the diagonal sum has no string loop.
- ValueError
Masked text data whose diagonal does not parse as float64, or an
outof the wrong rank.
transpose(params int[])
Permute axes (mask transposed alike), NumPy's MaskedArray.transpose(*axes); reverses all axes
without an argument.
public NDMaskedArray transpose(params int[] axes)
Parameters
axesint[]NumPy's
*axes: the permutation as separate integers (m.transpose(1, 0)) or one array; no argument, an empty array ornullreverses the axes (C# passes an empty array for the no-argument call, so the two read alike).
Returns
- NDMaskedArray
The transposed masked array.
Exceptions
- ValueError
The permutation does not have one entry per axis (
axes don't match array) or repeats an axis.- AxisError
An axis is out of bounds.
unshare_mask()
Ensures the mask is not shared with any other array (NumPy's unshare_mask) by COPYING it,
then returns this array. Reach for it before a mutating write when the mask may be aliased — the
view-returning members (real/imag/view(DType, object) and a
basic-slice index) share the mask reference, so an in-place mask write would otherwise reach the
source. A no-op for a nomask array.
public NDMaskedArray unshare_mask()
Returns
- NDMaskedArray
This masked array (with an owned mask).
Remarks
NumSharp cannot track whether a mask is actually shared (there is no sharedmask state),
so — unlike NumPy, which copies only WHEN shared — this copies unconditionally when a mask is present;
the end state (an unshared mask) is identical, only a redundant copy of an already-owned mask differs.
Ownership. The new copy is a field store: it is detached from every ambient scope
(Own(NDArray)) so it lives as long as this array — a scope open around the call
must not dispose the mask this array now holds. The SUPERSEDED mask is deliberately NOT disposed: the
whole point of unsharing is that other arrays may still read it, so it stays with whoever created it
(released when they dispose it, else by the finalizer). A caller that knows it was the only holder can
read mask first and dispose that buffer itself after the call.
var(int, DType, NDMaskedArray, int, bool, object)
The owner's kept int form of var(NDAxis?, DType, NDMaskedArray, int, bool, object).
public NDMaskedArray var(int axis, DType dtype = null, NDMaskedArray @out = null, int ddof = 0, bool keepdims = false, object mean = null)
Parameters
axisintThe one axis to reduce (negative counts from the end).
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).ddofintDelta degrees of freedom: the divisor is the count minus
ddof.keepdimsboolKeep the reduced axes with length 1.
meanobjectNumPy 2's precomputed mean, or null to compute it.
Returns
- NDMaskedArray
The masked variance, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- AttributeError
A 0-d result of a masked operand into a masked
out(NumPy's numpy scalar has nomask).- MaskError
A masked 0-d result into a plain integer or bool
out.
var(int[], DType, NDMaskedArray, int, bool, object)
The owner's kept int[] form of var(NDAxis?, DType, NDMaskedArray, int, bool, object).
public NDMaskedArray var(int[] axis, DType dtype = null, NDMaskedArray @out = null, int ddof = 0, bool keepdims = false, object mean = null)
Parameters
axisint[]The axes to reduce, or null (NumPy's None) for every axis.
dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).ddofintDelta degrees of freedom: the divisor is the count minus
ddof.keepdimsboolKeep the reduced axes with length 1.
meanobjectNumPy 2's precomputed mean, or null to compute it.
Returns
- NDMaskedArray
The masked variance, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- AttributeError
A 0-d result of a masked operand into a masked
out(NumPy's numpy scalar has nomask).- MaskError
A masked 0-d result into a plain integer or bool
out.
var(NDAxis?, DType, NDMaskedArray, int, bool, object)
Variance over the unmasked elements — NumPy's MaskedArray.var(axis=None, dtype=None, out=None, ddof=0, keepdims, mean).
public NDMaskedArray var(NDAxis? axis = null, DType dtype = null, NDMaskedArray @out = null, int ddof = 0, bool keepdims = false, object mean = null)
Parameters
axisNDAxis?The axis or axes to reduce — an int, a tuple or an
int[](negative counts from the end) — or null for every axis.dtypeDTypeThe accumulator / result dtype, or null for NumPy's default.
outNDMaskedArrayWhere to write the result, or null for a new one: a masked array receives the data and the mask, a plain NDArray converts and receives the data only (NumPy reads
isinstance(out, MaskedArray)).ddofintDelta degrees of freedom: the divisor is the count minus
ddof.keepdimsboolKeep the reduced axes with length 1.
meanobjectNumPy 2's precomputed mean, or null to compute it.
Returns
- NDMaskedArray
The masked variance, or
out.
Exceptions
- AxisError
An axis is out of range.
- ValueError
A repeated axis, or an
outwhose shape does not match the result.- AttributeError
A 0-d result of a masked operand into a masked
out(NumPy's numpy scalar has nomask).- MaskError
A masked 0-d result into a plain integer or bool
out.
view(DType, object)
Reinterprets the data buffer as another dtype (NumPy's MaskedArray.view) — a VIEW sharing
memory, writes through. A same-itemsize dtype (e.g. int32↔uint32↔float32) or the no-dtype call
keeps the shape, so the boolean mask still aligns and rides through unchanged.
public NDMaskedArray view(DType dtype = null, object fill_value = null)
Parameters
dtypeDTypeTarget dtype; null ⇒ a same-dtype alias. Any dtype — the same one too — resets a stored fill value to the dtype default (NumPy's
view).fill_valueobjectA new fill value for the view (NumPy's
fill_value=); it replaces a STORED fill only — on an array whose fill was never set or read it is ignored, as in NumPy — and is written into the view's own copy of the fill, at THIS array's dtype (a float64 array'sview(int64, fill_value: 3)reads back double 3.0, as NumPy's does).
Returns
- NDMaskedArray
A masked array over the reinterpreted data, with this array's hard-mask flag and a COPY of its stored fill (NumPy's
array_finalize, which runs before the new dtype is set); the mask is carried as a view when the shape is preserved, and is absent (nomask) for an itemsize-changing view of an unmasked array.
Exceptions
- IncorrectShapeException
The target dtype has a different itemsize AND this array has a mask: NumPy's dtype setter reshapes the mask to the view's shape and raises
ValueError: cannot reshape array of size 4 into shape (16,)(NumSharp's house type for that ValueError). Until 2026-10-08 a NotSupportedException with NumSharp's own text.
Operators
operator +(NDArray, NDMaskedArray)
Masked sum with an NDArray left operand.
public static NDMaskedArray operator +(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a+b, masked.
operator +(NDMaskedArray, NDArray)
Masked sum with an NDArray operand (mask = the masked operand's).
public static NDMaskedArray operator +(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight.
Returns
- NDMaskedArray
a+b, masked.
operator +(NDMaskedArray, NDMaskedArray)
Masked element-wise sum (mask = OR of operands').
public static NDMaskedArray operator +(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a+b, masked.
operator +(NDMaskedArray, object)
Masked sum with a scalar/array-like right operand.
public static NDMaskedArray operator +(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a+b, masked.
operator +(object, NDMaskedArray)
Masked sum with a scalar/array-like left operand.
public static NDMaskedArray operator +(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a+b, masked.
operator &(NDArray, NDMaskedArray)
Masked bitwise AND with an NDArray left operand.
public static NDMaskedArray operator &(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a&b, masked.
operator &(NDMaskedArray, NDArray)
Masked bitwise AND with an NDArray operand.
public static NDMaskedArray operator &(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight NDArray.
Returns
- NDMaskedArray
a&b, masked.
operator &(NDMaskedArray, NDMaskedArray)
Masked bitwise AND (mask = OR of operands').
public static NDMaskedArray operator &(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a&b, masked.
operator &(NDMaskedArray, object)
Masked bitwise AND with a scalar/array-like.
public static NDMaskedArray operator &(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a&b, masked.
operator &(object, NDMaskedArray)
Masked bitwise AND with a scalar/array-like left operand.
public static NDMaskedArray operator &(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a&b, masked.
operator |(NDArray, NDMaskedArray)
Masked bitwise OR with an NDArray left operand.
public static NDMaskedArray operator |(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a|b, masked.
operator |(NDMaskedArray, NDArray)
Masked bitwise OR with an NDArray operand.
public static NDMaskedArray operator |(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight NDArray.
Returns
- NDMaskedArray
a|b, masked.
operator |(NDMaskedArray, NDMaskedArray)
Masked bitwise OR (mask = OR of operands').
public static NDMaskedArray operator |(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a|b, masked.
operator |(NDMaskedArray, object)
Masked bitwise OR with a scalar/array-like.
public static NDMaskedArray operator |(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a|b, masked.
operator |(object, NDMaskedArray)
Masked bitwise OR with a scalar/array-like left operand.
public static NDMaskedArray operator |(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a|b, masked.
operator /(NDArray, NDMaskedArray)
Masked division with an NDArray numerator.
public static NDMaskedArray operator /(NDArray a, NDMaskedArray b)
Parameters
aNDArrayNumerator NDArray.
bNDMaskedArrayDenominator masked array.
Returns
- NDMaskedArray
a/b, masked.
operator /(NDMaskedArray, NDArray)
Masked division with an NDArray denominator.
public static NDMaskedArray operator /(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayNumerator.
bNDArrayDenominator NDArray.
Returns
- NDMaskedArray
a/b, masked.
operator /(NDMaskedArray, NDMaskedArray)
Masked element-wise true division (unsafe divides are additionally masked).
public static NDMaskedArray operator /(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayNumerator.
bNDMaskedArrayDenominator.
Returns
- NDMaskedArray
a/b, masked.
operator /(NDMaskedArray, object)
Masked division with a scalar/array-like denominator.
public static NDMaskedArray operator /(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayNumerator masked array.
bobjectDenominator scalar/array-like.
Returns
- NDMaskedArray
a/b, masked.
operator /(object, NDMaskedArray)
Masked division with a scalar/array-like numerator.
public static NDMaskedArray operator /(object a, NDMaskedArray b)
Parameters
aobjectNumerator scalar/array-like.
bNDMaskedArrayDenominator masked array.
Returns
- NDMaskedArray
a/b, masked.
operator ^(NDArray, NDMaskedArray)
Masked bitwise XOR with an NDArray left operand.
public static NDMaskedArray operator ^(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a^b, masked.
operator ^(NDMaskedArray, NDArray)
Masked bitwise XOR with an NDArray operand.
public static NDMaskedArray operator ^(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight NDArray.
Returns
- NDMaskedArray
a^b, masked.
operator ^(NDMaskedArray, NDMaskedArray)
Masked bitwise XOR (mask = OR of operands').
public static NDMaskedArray operator ^(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a^b, masked.
operator ^(NDMaskedArray, object)
Masked bitwise XOR with a scalar/array-like.
public static NDMaskedArray operator ^(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a^b, masked.
operator ^(object, NDMaskedArray)
Masked bitwise XOR with a scalar/array-like left operand.
public static NDMaskedArray operator ^(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a^b, masked.
operator >(NDArray, NDMaskedArray)
Masked greater-than with an NDArray left operand.
public static NDMaskedArray operator >(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a>b, masked bool.
operator >(NDMaskedArray, NDArray)
Masked greater-than with an NDArray operand.
public static NDMaskedArray operator >(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight.
Returns
- NDMaskedArray
a>b, masked bool.
operator >(NDMaskedArray, NDMaskedArray)
Masked element-wise greater-than.
public static NDMaskedArray operator >(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a>b, masked bool.
operator >(NDMaskedArray, object)
Masked greater-than against a scalar/array-like.
public static NDMaskedArray operator >(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a>b, masked bool.
operator >(object, NDMaskedArray)
Masked greater-than with a scalar/array-like left operand.
public static NDMaskedArray operator >(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a>b, masked bool.
operator >=(NDArray, NDMaskedArray)
Masked greater-or-equal with an NDArray left operand.
public static NDMaskedArray operator >=(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a>=b, masked bool.
operator >=(NDMaskedArray, NDArray)
Masked greater-or-equal with an NDArray operand.
public static NDMaskedArray operator >=(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight.
Returns
- NDMaskedArray
a>=b, masked bool.
operator >=(NDMaskedArray, NDMaskedArray)
Masked element-wise greater-or-equal.
public static NDMaskedArray operator >=(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a>=b, masked bool.
operator >=(NDMaskedArray, object)
Masked greater-or-equal against a scalar/array-like.
public static NDMaskedArray operator >=(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a>=b, masked bool.
operator >=(object, NDMaskedArray)
Masked greater-or-equal with a scalar/array-like left operand.
public static NDMaskedArray operator >=(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a>=b, masked bool.
implicit operator NDMaskedArray(NDArray)
Adopts a plain NDArray as an unmasked NDMaskedArray (no element
masked), so every np.ma.* function accepts a bare array argument exactly as NumPy does.
public static implicit operator NDMaskedArray(NDArray a)
Parameters
aNDArrayThe array to wrap; null yields null.
Returns
- NDMaskedArray
A mask-less view of
a's own data (writes reacha), marked NumSharp.NDMaskedArray.IsPlainArrayWrapper.
operator <(NDArray, NDMaskedArray)
Masked less-than with an NDArray left operand.
public static NDMaskedArray operator <(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a<b, masked bool.
operator <(NDMaskedArray, NDArray)
Masked less-than with an NDArray operand.
public static NDMaskedArray operator <(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight.
Returns
- NDMaskedArray
a<b, masked bool.
operator <(NDMaskedArray, NDMaskedArray)
Masked element-wise less-than.
public static NDMaskedArray operator <(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a<b, masked bool.
operator <(NDMaskedArray, object)
Masked less-than against a scalar/array-like.
public static NDMaskedArray operator <(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a<b, masked bool.
operator <(object, NDMaskedArray)
Masked less-than with a scalar/array-like left operand.
public static NDMaskedArray operator <(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a<b, masked bool.
operator <=(NDArray, NDMaskedArray)
Masked less-or-equal with an NDArray left operand.
public static NDMaskedArray operator <=(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a<=b, masked bool.
operator <=(NDMaskedArray, NDArray)
Masked less-or-equal with an NDArray operand.
public static NDMaskedArray operator <=(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight.
Returns
- NDMaskedArray
a<=b, masked bool.
operator <=(NDMaskedArray, NDMaskedArray)
Masked element-wise less-or-equal.
public static NDMaskedArray operator <=(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a<=b, masked bool.
operator <=(NDMaskedArray, object)
Masked less-or-equal against a scalar/array-like.
public static NDMaskedArray operator <=(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a<=b, masked bool.
operator <=(object, NDMaskedArray)
Masked less-or-equal with a scalar/array-like left operand.
public static NDMaskedArray operator <=(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a<=b, masked bool.
operator %(NDArray, NDMaskedArray)
Masked modulo with an NDArray numerator.
public static NDMaskedArray operator %(NDArray a, NDMaskedArray b)
Parameters
aNDArrayNumerator NDArray.
bNDMaskedArrayDivisor masked array.
Returns
- NDMaskedArray
a%b, masked.
operator %(NDMaskedArray, NDArray)
Masked modulo with an NDArray divisor.
public static NDMaskedArray operator %(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayNumerator.
bNDArrayDivisor NDArray.
Returns
- NDMaskedArray
a%b, masked.
operator %(NDMaskedArray, NDMaskedArray)
Masked element-wise modulo (division-by-zero additionally masked).
public static NDMaskedArray operator %(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayNumerator.
bNDMaskedArrayDivisor.
Returns
- NDMaskedArray
a%b, masked.
operator %(NDMaskedArray, object)
Masked modulo with a scalar/array-like divisor.
public static NDMaskedArray operator %(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayNumerator masked array.
bobjectDivisor scalar/array-like.
Returns
- NDMaskedArray
a%b, masked.
operator %(object, NDMaskedArray)
Masked modulo with a scalar/array-like numerator.
public static NDMaskedArray operator %(object a, NDMaskedArray b)
Parameters
aobjectNumerator scalar/array-like.
bNDMaskedArrayDivisor masked array.
Returns
- NDMaskedArray
a%b, masked.
operator *(NDArray, NDMaskedArray)
Masked product with an NDArray left operand.
public static NDMaskedArray operator *(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a*b, masked.
operator *(NDMaskedArray, NDArray)
Masked product with an NDArray operand.
public static NDMaskedArray operator *(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight.
Returns
- NDMaskedArray
a*b, masked.
operator *(NDMaskedArray, NDMaskedArray)
Masked element-wise product.
public static NDMaskedArray operator *(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a*b, masked.
operator *(NDMaskedArray, object)
Masked product with a scalar/array-like right operand.
public static NDMaskedArray operator *(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a*b, masked.
operator *(object, NDMaskedArray)
Masked product with a scalar/array-like left operand.
public static NDMaskedArray operator *(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a*b, masked.
operator ~(NDMaskedArray)
Bitwise NOT / invert, NumPy's ~x: ndarray's invert runs np.bitwise_not on the
data and array_wrap wraps it (a masked slot holds the inverted data, the mask is the operand's own
mask object, the fill value and hard mask carry over). NumPy has no np.ma.invert module function.
public static NDMaskedArray operator ~(NDMaskedArray a)
Parameters
aNDMaskedArrayOperand.
Returns
- NDMaskedArray
~a, masked.
Exceptions
- TypeError
A float / complex / text operand (np.invert's refusal).
operator -(NDArray, NDMaskedArray)
Masked difference with an NDArray left operand.
public static NDMaskedArray operator -(NDArray a, NDMaskedArray b)
Parameters
aNDArrayLeft NDArray.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a-b, masked.
operator -(NDMaskedArray, NDArray)
Masked difference with an NDArray operand.
public static NDMaskedArray operator -(NDMaskedArray a, NDArray b)
Parameters
aNDMaskedArrayLeft.
bNDArrayRight.
Returns
- NDMaskedArray
a-b, masked.
operator -(NDMaskedArray, NDMaskedArray)
Masked element-wise difference.
public static NDMaskedArray operator -(NDMaskedArray a, NDMaskedArray b)
Parameters
aNDMaskedArrayLeft.
bNDMaskedArrayRight.
Returns
- NDMaskedArray
a-b, masked.
operator -(NDMaskedArray, object)
Masked difference with a scalar/array-like right operand.
public static NDMaskedArray operator -(NDMaskedArray a, object b)
Parameters
aNDMaskedArrayLeft masked array.
bobjectRight scalar/array-like.
Returns
- NDMaskedArray
a-b, masked.
operator -(object, NDMaskedArray)
Masked difference with a scalar/array-like left operand.
public static NDMaskedArray operator -(object a, NDMaskedArray b)
Parameters
aobjectLeft scalar/array-like.
bNDMaskedArrayRight masked array.
Returns
- NDMaskedArray
a-b, masked.
operator -(NDMaskedArray)
Element-wise negation, NumPy's -x: MaskedArray defines no neg, so ndarray's runs the
plain np.negative and array_wrap wraps it (see UfuncOperator(NDMaskedArray, Func<NDArray, NDArray>)):
a masked slot holds the negated data (where negative(object, NDMaskedArray, NDArray, DType) writes the operand's data
back), the mask is the operand's own mask object, and the fill value and hard mask carry over.
public static NDMaskedArray operator -(NDMaskedArray a)
Parameters
aNDMaskedArrayOperand.
Returns
- NDMaskedArray
-a, masked.
Exceptions
- TypeError
A bool or text operand (np.negative's refusal).