Struct np.Intersect1dResult
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
The result of <xref href="NumSharp.np.intersect1d(NumSharp.NDArray%2cNumSharp.NDArray%2cSystem.Boolean%2cSystem.Boolean)" data-throw-if-not-resolved="false"></xref> — NumPy's bare-array-OR-tuple return
expressed as one type (np.unique's <xref href="NumSharp.np.UniqueResult" data-throw-if-not-resolved="false"></xref> pattern): the sorted common
<xref href="NumSharp.np.Intersect1dResult.values" data-throw-if-not-resolved="false"></xref>, plus <xref href="NumSharp.np.Intersect1dResult.comm1" data-throw-if-not-resolved="false"></xref> / <xref href="NumSharp.np.Intersect1dResult.comm2" data-throw-if-not-resolved="false"></xref> when <code>return_indices</code> was set (null
otherwise).
It stands in for both NumPy return shapes: it converts implicitly to NDArray (the bare
form, the values: NDArray v = np.intersect1d(a, b);) and implicitly to NDArray[]
(the tuple form, the present outputs in NumPy's order), indexes the outputs ([1] is comm1), and
deconstructs: var (values, comm1, comm2) = np.intersect1d(a, b, return_indices: true);.
public readonly struct np.Intersect1dResult : INDArrayCarrier, IDisposable
- Implements
- Inherited Members
Remarks
API-parity batch 11 (2026-11-13): it replaces the two NDArray-returning overloads and the
NDArray[]-returning one. Assignment and argument passing are unaffected (the implicit
conversions); the common NDArray members forward to values (size, shape, dtype, the typed
getters, ToArray<T>, array_equal), and Dispose() releases every output, so
using var r = np.intersect1d(...) keeps working.
Footgun: an extension method of NDArray (FluentAssertions' Should(), a LINQ-style
helper) does not see through the implicit conversion - call it on values, or assign the
result to an NDArray first.
Properties
this[int]
The index-th present output in NumPy's order (values, comm1, comm2).
public NDArray this[int index] { get; }
Parameters
indexint0 for the values, 1 and 2 for the index arrays.
Property Value
- NDArray
The output.
Exceptions
- IndexOutOfRangeException
indexis not below Length.
Length
Number of present outputs: 1, or 3 with return_indices (NumPy's tuple length).
public int Length { get; }
Property Value
Shape
public Shape Shape { get; }
Property Value
comm1
The indices of the first occurrences of the common values in ar1 (int64), or null
when return_indices was false.
public NDArray comm1 { get; }
Property Value
comm2
The indices of the first occurrences of the common values in ar2 (int64), or null
when return_indices was false.
public NDArray comm2 { get; }
Property Value
dtype
The descriptor of values (the two operands' common dtype).
public DType dtype { get; }
Property Value
ndim
Rank of values (always 1).
public int ndim { get; }
Property Value
shape
public long[] shape { get; }
Property Value
- long[]
size
Element count of values.
public long size { get; }
Property Value
typecode
The storage lane of values.
public NPTypeCode typecode { get; }
Property Value
values
The sorted 1-D array of common (unique) values. Always present.
public NDArray values { get; }
Property Value
Methods
Deconstruct(out NDArray, out NDArray, out NDArray)
Deconstructs a return_indices=True result: var (values, comm1, comm2) = ....
public void Deconstruct(out NDArray values, out NDArray comm1, out NDArray comm2)
Parameters
valuesNDArrayThe common values.
comm1NDArrayThe first-occurrence indices in
ar1.comm2NDArrayThe first-occurrence indices in
ar2.
Exceptions
- InvalidOperationException
The result holds only the values (Python's
not enough values to unpack (expected 3, got 1)).
Dispose()
Releases every present output (the values and the index arrays): the using form of a
result the caller is done with.
public void Dispose()
Remarks
Disposing the struct disposes the arrays it shares with every copy of it and with any variable the implicit conversions filled - dispose once, when none of them is read again.
GetAtIndex(long)
The element of values at a flat index, boxed in its own type.
public object GetAtIndex(long index)
Parameters
indexlongThe flat index.
Returns
- object
The element.
GetDouble(int[])
public double GetDouble(int[] indices)
Parameters
indicesint[]The coordinates.
Returns
- double
The element read as a double.
GetDouble(params long[])
public double GetDouble(params long[] indices)
Parameters
indiceslong[]The coordinates.
Returns
- double
The element read as a double.
GetInt32(params long[])
public int GetInt32(params long[] indices)
Parameters
indiceslong[]The coordinates.
Returns
- int
The element read as an int.
GetInt64(params long[])
public long GetInt64(params long[] indices)
Parameters
indiceslong[]The coordinates.
Returns
- long
The element read as a long.
ToArray()
The present outputs as an NDArray[] in NumPy's order.
public NDArray[] ToArray()
Returns
- NDArray[]
The outputs array (the struct's own; do not mutate it).
ToArray<T>()
The elements of values as a new T[] in C order.
public T[] ToArray<T>() where T : unmanaged
Returns
- T[]
A new managed array.
Type Parameters
TThe element type to read (it must be the dtype's own type, as ToArray<T>() requires).
Exceptions
- ArgumentException
Tis not the values' element type.
array_equal(NDArray)
True if values equals rhs element-wise (same shape).
public bool array_equal(NDArray rhs)
Parameters
rhsNDArrayThe array to compare with.
Returns
- bool
Whether the shapes and elements are equal.
Operators
implicit operator NDArray(Intersect1dResult)
Bare-return conversion: the values (NumPy's single-array return).
public static implicit operator NDArray(np.Intersect1dResult result)
Parameters
resultnp.Intersect1dResultThe result.
Returns
implicit operator NDArray[](Intersect1dResult)
Tuple-return conversion: the present outputs, NumPy's order.
public static implicit operator NDArray[](np.Intersect1dResult result)
Parameters
resultnp.Intersect1dResultThe result.
Returns
- NDArray[]
The outputs array.