Table of Contents

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

index int

Property Value

NDArray

Length

Number of present outputs (1 + one per requested return flag).

public int Length { get; }

Property Value

int

Shape

The Shape of values.

public Shape Shape { get; }

Property Value

Shape

counts

Per-value occurrence counts, or null when return_counts was False.

public NDArray counts { get; }

Property Value

NDArray

dtype

Element Type of values.

public DType dtype { get; }

Property Value

DType

indices

First-occurrence indices, or null when return_index was False.

public NDArray indices { get; }

Property Value

NDArray

inverse_indices

Reconstruction indices (shaped like the input), or null when return_inverse was False.

public NDArray inverse_indices { get; }

Property Value

NDArray

ndim

Rank of values.

public int ndim { get; }

Property Value

int

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

long

typecode

Element NPTypeCode of values.

public NPTypeCode typecode { get; }

Property Value

NPTypeCode

values

The sorted unique values (dtype preserved). Always present.

public NDArray values { get; }

Property Value

NDArray

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

values NDArray
second NDArray

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

values NDArray
second NDArray
third NDArray

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

values NDArray
index NDArray
inverse NDArray
counts NDArray

GetAtIndex(long)

The element of values at a flat index.

public object GetAtIndex(long index)

Parameters

index long

Returns

object

GetAtIndex<T>(long)

The T element of values at a flat index.

public T GetAtIndex<T>(long index) where T : unmanaged

Parameters

index long

Returns

T

Type Parameters

T

GetBoolean(int[])

The bool value of values at the given coordinates.

public bool GetBoolean(int[] indices)

Parameters

indices int[]

Returns

bool

GetBoolean(params long[])

The bool value of values at the given coordinates.

public bool GetBoolean(params long[] indices)

Parameters

indices long[]

Returns

bool

GetDouble(int[])

The double value of values at the given coordinates.

public double GetDouble(int[] indices)

Parameters

indices int[]

Returns

double

GetDouble(params long[])

The double value of values at the given coordinates.

public double GetDouble(params long[] indices)

Parameters

indices long[]

Returns

double

GetInt32(params long[])

The int value of values at the given coordinates.

public int GetInt32(params long[] indices)

Parameters

indices long[]

Returns

int

GetSingle(int[])

The float value of values at the given coordinates.

public float GetSingle(int[] indices)

Parameters

indices int[]

Returns

float

GetSingle(params long[])

The float value of values at the given coordinates.

public float GetSingle(params long[] indices)

Parameters

indices long[]

Returns

float

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

rhs NDArray

Returns

bool

Operators

implicit operator NDArray(UniqueResult)

Bare-return conversion: yields values (NumPy's single-array return).

public static implicit operator NDArray(np.UniqueResult result)

Parameters

result np.UniqueResult

Returns

NDArray

implicit operator NDArray[](UniqueResult)

Tuple-return conversion: the present outputs, NumPy field order.

public static implicit operator NDArray[](np.UniqueResult result)

Parameters

result np.UniqueResult

Returns

NDArray[]