mars.tensor.mgrid¶

mars.tensor.
mgrid
= <mars.tensor.lib.index_tricks.nd_grid object>¶ Construct a multidimensional “meshgrid”.
grid = nd_grid()
creates an instance which will return a meshgrid when indexed. 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.
If instantiated with an argument of
sparse=True
, the meshgrid is open (or not fleshed out) so that only onedimension of each returned argument is greater than 1. Parameters
sparse (bool, optional) – Whether the grid is sparse or not. Default is False.
Notes
Two instances of nd_grid are made available in the Mars.tensor namespace, mgrid and ogrid:
mgrid = nd_grid(sparse=False) ogrid = nd_grid(sparse=True)
Users should use these predefined instances instead of using nd_grid directly.
Examples
>>> import mars.tensor as mt
>>> mgrid = mt.lib.index_tricks.nd_grid() >>> 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]]]) >>> mgrid[1:1:5j] array([1. , 0.5, 0. , 0.5, 1. ])
>>> ogrid = mt.lib.index_tricks.nd_grid(sparse=True) >>> ogrid[0:5,0:5] [array([[0], [1], [2], [3], [4]]), array([[0, 1, 2, 3, 4]])]