Table of Contents

Struct np.OGridResult

Namespace
NumSharp
Assembly
NumSharp.dll

The result of an ogrid index expression: an open mesh — a set of N arrays, each 1 in every axis but its own. NumPy's ogrid is polymorphic (a single slice yields a bare ndarray, several slices yield a tuple), which C# cannot express from one indexer, so this value stands in for both:

  • a single-slice result converts implicitly to a bare NDArray;
  • any result converts implicitly to NDArray[] and can be Deconstructed (var (y, x) = np.ogrid["0:3", "0:5"];) or indexed ([k]).
public readonly struct np.OGridResult : INDArrayCarrier
Implements
Inherited Members

Remarks

This collapses NumPy's bare-array-vs-1-tuple distinction (Python's ogrid[0:5] vs ogrid[0:5,]): both spell np.ogrid["0:5"] here, and the single stored array is reachable as an NDArray or as a length-1 NDArray[].

Properties

this[int]

The k-th mesh array (shape 1 in every axis but the k-th).

public NDArray this[int index] { get; }

Parameters

index int

Property Value

NDArray

Length

Number of arrays in the mesh (one per slice given to ogrid).

public int Length { get; }

Property Value

int

Methods

Deconstruct(out NDArray, out NDArray)

Deconstructs a two-slice mesh: var (y, x) = np.ogrid["0:3", "0:5"];

public void Deconstruct(out NDArray item1, out NDArray item2)

Parameters

item1 NDArray
item2 NDArray

Deconstruct(out NDArray, out NDArray, out NDArray)

Deconstructs a three-slice mesh.

public void Deconstruct(out NDArray item1, out NDArray item2, out NDArray item3)

Parameters

item1 NDArray
item2 NDArray
item3 NDArray

Deconstruct(out NDArray, out NDArray, out NDArray, out NDArray)

Deconstructs a four-slice mesh.

public void Deconstruct(out NDArray item1, out NDArray item2, out NDArray item3, out NDArray item4)

Parameters

item1 NDArray
item2 NDArray
item3 NDArray
item4 NDArray

ToArray()

Returns the mesh arrays as an NDArray[].

public NDArray[] ToArray()

Returns

NDArray[]

Operators

implicit operator NDArray(OGridResult)

Unwraps a SINGLE-slice result to the bare NDArray NumPy returns for ogrid[0:5]. Throws for a multi-slice result — that outcome is ambiguous, use the NDArray[] conversion, Deconstruct or indexing instead.

public static implicit operator NDArray(np.OGridResult result)

Parameters

result np.OGridResult

Returns

NDArray

implicit operator NDArray[](OGridResult)

Exposes the whole open mesh — the natural form for a multi-slice np.ogrid[…] (a single-slice result comes back as a length-1 array).

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

Parameters

result np.OGridResult

Returns

NDArray[]