# NumPy mgrid vs. meshgrid

The meshgrid function is useful for creating coordinate arrays to
vectorize function evaluations over a grid. Experienced NumPy users will have
noticed some discrepancy between `meshgrid` and the mgrid, a function
that is used just as often, for exactly the same purpose. What is the
discrepancy, and why does a discrepancy even exist when *"there should be one
- and preferably only one - obvious way to do it."* [1]

First, recall that `meshgrid` behaves as follows:

>>> import numpy as np >>> x1, y1 = np.meshgrid(np.arange(1, 11, 2), np.arange(-12, -3, 3)) >>> x1 # 3x5 array array([[1, 3, 5, 7, 9], [1, 3, 5, 7, 9], [1, 3, 5, 7, 9]]) >>> y1 # 3x5 array array([[-12, -12, -12, -12, -12], [ -9, -9, -9, -9, -9], [ -6, -6, -6, -6, -6]])