Struct np.UniqueResult
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The result of <xref href="NumSharp.np.unique(NumSharp.NDArray%2cSystem.Boolean%2cSystem.Boolean%2cSystem.Boolean%2cSystem.Nullable%7bSystem.Int32%7d%2cSystem.Boolean%2cSystem.Boolean)" data-throw-if-not-resolved="false"></xref> — NumPy's
bare-array-OR-tuple return expressed as one type. It carries the sorted unique
<xref href="NumSharp.np.UniqueResult.values" data-throw-if-not-resolved="false"></xref> plus whichever of <xref href="NumSharp.np.UniqueResult.indices" data-throw-if-not-resolved="false"></xref>/<xref href="NumSharp.np.UniqueResult.inverse_indices" data-throw-if-not-resolved="false"></xref>/
<xref href="NumSharp.np.UniqueResult.counts" data-throw-if-not-resolved="false"></xref> were requested (the others are <code>null</code>), so
<code>np.unique(ar, return_counts=True)</code> ports from Python verbatim.
It stands in for both NumPy return shapes: it converts implicitly to
NDArray (the bare form — yields values, so
NDArray u = np.unique(ar); works) and implicitly to NDArray[]
(the tuple form — the present outputs in NumPy field order). It also indexes
([k] = the k-th present output, matching the old NDArray[] return) and
Deconstructs (var (values, counts) = np.unique(ar, return_counts: true);).
public readonly struct np.UniqueResult : INDArrayCarrier
- Implements
- Inherited Members
Remarks
BREAKING vs the pre-2.4.2-parity API: np.unique(ar) now returns this struct rather
than a bare NDArray. Assignment and argument passing are unaffected (implicit
conversion), but chaining an NDArray member directly on the result
(np.unique(ar).array_equal(...)) needs .values, and np.unique(ar)[k]
now selects the k-th OUTPUT (values, index, …), not the k-th unique value — use
np.unique(ar).values[k] for the latter. The instance
unique(int?, bool, bool) / unique(bool, bool, bool, int?, bool, bool)
still return NDArray/NDArray[] unchanged.
Properties
this[int]
The k-th present output in NumPy field order (values, then index/inverse/counts as requested).
public NDArray this[int index] { get; }
Parameters
indexint
Property Value
Length
Number of present outputs (1 + one per requested return flag).
public int Length { get; }
Property Value
Shape
public Shape Shape { get; }
Property Value
counts
Per-value occurrence counts, or null when return_counts was False.
public NDArray counts { get; }
Property Value
dtype
public DType dtype { get; }
Property Value
indices
First-occurrence indices, or null when return_index was False.
public NDArray indices { get; }
Property Value
inverse_indices
Reconstruction indices (shaped like the input), or null when return_inverse was False.
public NDArray inverse_indices { get; }
Property Value
ndim
Rank of values.
public int ndim { get; }
Property Value
shape
Shape of values as a long[].
public long[] shape { get; }
Property Value
- long[]
size
Element count of values.
public long size { get; }
Property Value
typecode
Element NPTypeCode of values.
public NPTypeCode typecode { get; }
Property Value
values
The sorted unique values (dtype preserved). Always present.
public NDArray values { get; }
Property Value
Methods
Deconstruct(out NDArray, out NDArray)
Deconstructs into the first two present outputs (e.g. (values, counts)).
public void Deconstruct(out NDArray values, out NDArray second)
Parameters
Deconstruct(out NDArray, out NDArray, out NDArray)
Deconstructs into the first three present outputs.
public void Deconstruct(out NDArray values, out NDArray second, out NDArray third)
Parameters
Deconstruct(out NDArray, out NDArray, out NDArray, out NDArray)
Deconstructs into all four outputs (requires every return flag set).
public void Deconstruct(out NDArray values, out NDArray index, out NDArray inverse, out NDArray counts)
Parameters
GetAtIndex(long)
The element of values at a flat index.
public object GetAtIndex(long index)
Parameters
indexlong
Returns
GetAtIndex<T>(long)
The T element of values at a flat index.
public T GetAtIndex<T>(long index) where T : unmanaged
Parameters
indexlong
Returns
- T
Type Parameters
T
GetBoolean(int[])
public bool GetBoolean(int[] indices)
Parameters
indicesint[]
Returns
GetBoolean(params long[])
public bool GetBoolean(params long[] indices)
Parameters
indiceslong[]
Returns
GetDouble(int[])
public double GetDouble(int[] indices)
Parameters
indicesint[]
Returns
GetDouble(params long[])
public double GetDouble(params long[] indices)
Parameters
indiceslong[]
Returns
GetInt32(params long[])
public int GetInt32(params long[] indices)
Parameters
indiceslong[]
Returns
GetSingle(int[])
public float GetSingle(int[] indices)
Parameters
indicesint[]
Returns
GetSingle(params long[])
public float GetSingle(params long[] indices)
Parameters
indiceslong[]
Returns
ToArray()
The present outputs as an NDArray[] in NumPy field order.
public NDArray[] ToArray()
Returns
- NDArray[]
array_equal(NDArray)
True if values equals rhs element-wise (same shape).
public bool array_equal(NDArray rhs)
Parameters
rhsNDArray
Returns
Operators
implicit operator NDArray(UniqueResult)
Bare-return conversion: yields values (NumPy's single-array return).
public static implicit operator NDArray(np.UniqueResult result)
Parameters
resultnp.UniqueResult
Returns
implicit operator NDArray[](UniqueResult)
Tuple-return conversion: the present outputs, NumPy field order.
public static implicit operator NDArray[](np.UniqueResult result)
Parameters
resultnp.UniqueResult
Returns
- NDArray[]