NumPy: mgrid() function
The mgrid() function is used to get a dense multi-dimensional 'meshgrid'.
An instance of numpy.lib.index_tricks.nd_grid which returns an dense (or fleshed out) mesh-grid when indexed, so that each returned argument has the same shape. The dimensions 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.
numpy.mgrid = <numpy.lib.index_tricks.nd_grid object>
mesh-grid 'ndarrays' all of the same dimensions.
Example-1: NumPy.mgrid() function
>>> import numpy as np >>> import numpy as np >>> np.mgrid[0:4, 0:4] array([[[0, 0, 0, 0], [1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3]], [[0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]]])
Example-2: NumPy.mgrid() function
>>> import numpy as np >>> np.mgrid[-2:2:4j] array([-2. , -0.66666667, 0.66666667, 2. ])
Python - NumPy Code Editor:
- Weekly Trends
- Java Basic Programming Exercises
- SQL Subqueries
- Adventureworks Database Exercises
- C# Sharp Basic Exercises
- SQL COUNT() with distinct
- Java Collection Exercises
- SQL COUNT() function
- SQL Inner Join
- Python Tutorial
- Python Array Exercises
- SQL Cross Join
- C# Sharp Array Exercises