Class np.MGridClass
- Namespace
- NumSharp
- Assembly
- NumSharp.dll
An instance which returns a dense ("fleshed out") multi-dimensional "meshgrid" when
indexed, so that every returned axis-grid has the SAME shape. The number of stacked grids and
their dimensionality 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.MGridClass
- Inheritance
-
np.MGridClass
- Inherited Members
Examples
NDArray x = np.mgrid["-1:1:5j"]; // array([-1., -0.5, 0., 0.5, 1.])
var (rows, cols) = np.mgrid["0:5", "0:3"]; // each shape (5, 3)
NDArray stacked = np.mgrid["0:5", "0:3"]; // shape (2, 5, 3)
Remarks
Port of NumPy 2.x numpy.mgrid (the sparse=False instance of
numpy.lib.index_tricks.nd_grid). It is the DENSE twin of ogrid and shares
its whole grammar and dtype/edge-case behaviour (see np.OGridClass and the shared
NdGridLines builder): slices are written as strings (np.mgrid["0:5", "0:3"] ≙
np.mgrid[0:5, 0:3]); one string may carry comma-separated slices; Slice
objects work; there are NO directives. The mesh shares ONE dtype (int64 unless a float literal
or imaginary step appears, then float64); a multi-slice mesh requires an explicit stop on every
slice.
Shape. A single slice returns a bare 1-D array; N slices return the stacked array of
shape (N, size_0, …, size_{N-1}) — result[k] is the k-th coordinate broadcast
across the whole grid. It equals stack([broadcast_to(o, full) for o in ogrid[…]], axis:0)
(NumPy builds it as indices(sizes) then rescales each layer — same values, same layout).
Return. The np.MGridResult is NumPy's single array: it converts implicitly to
NDArray and Deconstructs / indexes into the per-axis grids.
https://numpy.org/doc/stable/reference/generated/numpy.mgrid.html
Properties
this[object[]]
Expands the slice expression into a dense mesh. See np.MGridClass for how a Python slice literal is spelled in C#.
public np.MGridResult 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.