Struct MaskedArrayModule.UniqueResult
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The result of unique(object, bool, bool): NumPy's bare masked array (no flag) or its
(MaskedArray, ndarray[, ndarray]) tuple (a flag), as one type. It converts implicitly to
NDMaskedArray (the values), deconstructs into the present outputs, indexes them in NumPy's
order, and forwards the masked array's members (data, mask, fill_value, hardmask, shape, dtype, size) to
its values, so a flag-less result reads like the masked array it stands for.
public readonly struct MaskedArrayModule.UniqueResult : INDArrayCarrier
- Implements
- Inherited Members
Remarks
NumPy returns a bare masked array without flags and a tuple with them; C# cannot vary a return type on a
runtime flag, so every call returns this struct. Its constructor is internal: only np.ma.unique builds it,
so values is always the masked result, typed NDMaskedArray (a deconstructed
var (u, idx) = ... gives the masked array statically).
API-parity batch 11: the flag-less NDMaskedArray unique(object ar1) overload went (the owner's
reading B: numpy.ma keeps its own typed result rather than sharing np.unique's).
Footgun: an extension method of NDMaskedArray does not see through the implicit conversion - call it on values.
Properties
this[int]
The index-th present output in NumPy's order: the values, then the indices,
then the inverse.
public object this[int index] { get; }
Parameters
indexint0 for the values, then 1 and 2 for the present index arrays.
Property Value
- object
The NDMaskedArray values or an NDArray of indices.
Exceptions
- IndexOutOfRangeException
indexis not below Length (Python'sIndexError: tuple index out of range).
Length
The number of present outputs (1 plus one per requested flag), NumPy's tuple length.
public int Length { get; }
Property Value
data
The values' data: data (a view of the underlying array).
public NDArray data { get; }
Property Value
dtype
The values' dtype.
public DType dtype { get; }
Property Value
fill_value
The values' fill value (fill_value; the operand's, converted to the dtype).
public object fill_value { get; }
Property Value
hardmask
Whether the values' mask is hard (hardmask; a hard operand's is).
public bool hardmask { get; }
Property Value
indices
The first-occurrence indices (int64), or null when return_index was false.
public NDArray indices { get; }
Property Value
inverse_indices
The reconstruction indices (int64, shaped like the input), or null when
return_inverse was false.
public NDArray inverse_indices { get; }
Property Value
mask
The values' mask: mask (np.ma.nomask or a view of the mask).
public NDArray mask { get; }
Property Value
shape
The values' shape (1-D).
public long[] shape { get; }
Property Value
- long[]
size
The values' element count (masked slots included).
public long size { get; }
Property Value
values
The sorted unique values (NumPy's output[0].view(MaskedArray)). Always present.
public NDMaskedArray values { get; }
Property Value
Methods
Deconstruct(out NDMaskedArray, out NDArray)
Deconstructs a two-output result: var (u, inv) = np.ma.unique(a, return_inverse: true);
public void Deconstruct(out NDMaskedArray values, out NDArray second)
Parameters
valuesNDMaskedArrayThe unique values.
secondNDArrayThe one requested index array.
Exceptions
- InvalidOperationException
The result does not hold exactly two outputs (Python's unpacking ValueError).
Deconstruct(out NDMaskedArray, out NDArray, out NDArray)
Deconstructs a three-output result: var (u, idx, inv) = np.ma.unique(a, true, true);
public void Deconstruct(out NDMaskedArray values, out NDArray indices, out NDArray inverse_indices)
Parameters
valuesNDMaskedArrayThe unique values.
indicesNDArrayThe first-occurrence indices.
inverse_indicesNDArrayThe inverse indices.
Exceptions
- InvalidOperationException
The result does not hold three outputs.
Operators
implicit operator NDMaskedArray(UniqueResult)
The values: NumPy's first tuple element, and the whole result of a flag-less call.
public static implicit operator NDMaskedArray(MaskedArrayModule.UniqueResult result)
Parameters
resultMaskedArrayModule.UniqueResultThe result.