Class np.OGridClass
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
An instance which returns an open multi-dimensional "meshgrid" when indexed, so that only
one dimension of each returned array is greater than 1. The number and dimensionality of the
outputs equal the number of indexing slices. If the step length is not a complex number, the
stop is NOT inclusive; a complex step (e.g. "…:5j") instead specifies the number
of points, with the stop INCLUSIVE (i.e. linspace(double, double, long, bool, DType, string)).
public sealed class np.OGridClass
- Inheritance
-
np.OGridClass
- Inherited Members
Examples
NDArray x = np.ogrid["-1:1:5j"]; // array([-1., -0.5, 0., 0.5, 1.])
var (y, xx) = np.ogrid["0:5", "0:5"]; // y.shape (5,1), xx.shape (1,5)
NDArray[] g = np.ogrid["0:3", "0:4", "0:5"];
NDArray sum = np.ogrid["0:5", "0:5"][0] + np.ogrid["0:5", "0:5"][1]; // broadcast add
Remarks
Port of NumPy 2.x numpy.ogrid (the sparse=True instance of
numpy.lib.index_tricks.nd_grid). It shares the slice-expression grammar of
r_: C# has no a[1:5:2] literal, so a slice is written as a string —
np.ogrid["0:5"] ≙ np.ogrid[0:5] — and one string may carry several
comma-separated slices (np.ogrid["0:3, 0:5"]). Slice objects work as
entries too. Unlike r_ there are NO leading directives: every entry is a slice.
Dtype. All the slices of a multi-slice mesh share ONE dtype — int64 when every field of
every slice is an integer literal, else float64 (a complex step counts as non-integer). This
mirrors NumPy's single result_type(*num_list) over all the slice bounds: e.g.
np.ogrid["0:2", "0.0:2"] gives two float64 arrays, not one int64 and one float64.
A single-slice result keeps the literal-driven dtype of r_'s slice branch.
Missing stop. A single slice may omit its stop (np.ogrid["5:"] is
arange(0, 5), exactly like r_). A multi-slice mesh may NOT: NumPy needs the
stop to size each axis and leaks an AttributeError when it is absent, so NumSharp raises a
clear ValueError for np.ogrid["0:3", "5:"]. An imaginary step always
requires a stop (single or multi), also a ValueError.
Return. The np.OGridResult stands in for NumPy's array-or-tuple: a
single-slice result converts implicitly to a bare NDArray; a multi-slice result
converts to NDArray[], deconstructs, or indexes.
https://numpy.org/doc/stable/reference/generated/numpy.ogrid.html
Properties
this[object[]]
Expands the slice expression into an open mesh. See np.OGridClass for how a Python slice literal is spelled in C#.
public np.OGridResult this[params object[] key] { get; }
Parameters
keyobject[]Slice-expression strings (a colon-bearing
"start:stop[:step]", or several such comma-separated), and/or Slice objects.