numpy.mgrid#
- numpy.mgrid=<numpy.lib._index_tricks_impl.MGridClassobject>#
An instance which returns a dense multi-dimensional “meshgrid”.
An instance which returns a dense (or fleshed out) mesh-gridwhen indexed, so that each returned argument has the same shape.The dimensions and number of the output arrays are equal to thenumber of indexing dimensions. If the step length is not a complexnumber, then the stop is not inclusive.
However, if the step length is acomplex number (e.g. 5j), thenthe integer part of its magnitude is interpreted as specifying thenumber of points to create between the start and stop values, wherethe stop valueis inclusive.
- Returns:
- mesh-gridndarray
A single array, containing a set of
ndarrays all of the samedimensions. stacked along the first axis.
See also
ogridlike
mgridbut returns open (not fleshed out) mesh gridsmeshgridreturn coordinate matrices from coordinate vectors
r_array concatenator
- How to create arrays with regularly-spaced values
Examples
>>>importnumpyasnp>>>np.mgrid[0:5,0:5]array([[[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]]])>>>np.mgrid[-1:1:5j]array([-1. , -0.5, 0. , 0.5, 1. ])
>>>np.mgrid[0:4].shape(4,)>>>np.mgrid[0:4,0:5].shape(2, 4, 5)>>>np.mgrid[0:4,0:5,0:6].shape(3, 4, 5, 6)