# mindspore.numpy.mgrid¶

mindspore.numpy.mgrid()

mgrid is an NdGrid instance with sparse=False.

The dimension and number of the output arrays are equal to the number of indexing dimensions. If the step length is not a complex number, then the stop is not inclusive. However, if the step length is a complex number (e.g. 5j), then the integer part of its magnitude is interpreted as specifying the number of points to create between the start and stop values, where the stop value is inclusive.

Note

Not supported in graph mode. Unlike Numpy, if the step length is a complex number with a real component, the step length is handled as equivalent to int(abs(step)).

Returns

Tensor or tuple of tensor, a meshgrid.

Raises

TypeError – if slicing indices are not integers.

Supported Platforms:

Ascend GPU CPU

Examples

>>> from mindspore.numpy import mgrid
>>> output = mgrid[0:5, 0:5]
>>> print(output)
[[[0 0 0 0 0]
[1 1 1 1 1]
[2 2 2 2 2]
[3 3 3 3 3]
[4 4 4 4 4]]
[[0 1 2 3 4]
[0 1 2 3 4]
[0 1 2 3 4]
[0 1 2 3 4]
[0 1 2 3 4]]]
>>> output = mgrid[-1:1:5j]
>>> print(output)
[-1.  -0.5  0.   0.5  1. ]