dpnp.meshgrid

dpnp.meshgrid(*xi, copy=True, sparse=False, indexing='xy')[source]

Return coordinate matrices from coordinate vectors.

Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector fields over N-D grids, given one-dimensional coordinate arrays x1, x2,..., xn.

For full documentation refer to numpy.meshgrid.

Parameters:
  • x1 ({dpnp.ndarray, usm_ndarray}) -- 1-D arrays representing the coordinates of a grid.

  • x2 ({dpnp.ndarray, usm_ndarray}) -- 1-D arrays representing the coordinates of a grid.

  • ... ({dpnp.ndarray, usm_ndarray}) -- 1-D arrays representing the coordinates of a grid.

  • xn ({dpnp.ndarray, usm_ndarray}) -- 1-D arrays representing the coordinates of a grid.

  • indexing ({'xy', 'ij'}, optional) -- Cartesian ('xy', default) or matrix ('ij') indexing of output.

  • sparse (bool, optional) -- If True the shape of the returned coordinate array for dimension i is reduced from (N1, ..., Ni, ... Nn) to (1, ..., 1, Ni, 1, ..., 1). Default is False.

  • copy (bool, optional) -- If False, a view into the original arrays are returned in order to conserve memory. Default is True.

Returns:

X1, X2,..., XN -- For vectors x1, x2,..., xn with lengths Ni=len(xi), returns (N1, N2, N3,..., Nn) shaped arrays if indexing='ij' or (N2, N1, N3,..., Nn) shaped arrays if indexing='xy' with the elements of xi repeated to fill the matrix along the first dimension for x1, the second for x2 and so on.

Return type:

tuple of dpnp.ndarrays

Examples

>>> import dpnp as np
>>> nx, ny = (3, 2)
>>> x = np.linspace(0, 1, nx)
>>> y = np.linspace(0, 1, ny)
>>> xv, yv = np.meshgrid(x, y)
>>> xv
array([[0. , 0.5, 1. ],
       [0. , 0.5, 1. ]])
>>> yv
array([[0.,  0.,  0.],
       [1.,  1.,  1.]])
>>> xv, yv = np.meshgrid(x, y, sparse=True)  # make sparse output arrays
>>> xv
array([[0. ,  0.5,  1. ]])
>>> yv
array([[0.],
       [1.]])

meshgrid is very useful to evaluate functions on a grid.

>>> import matplotlib.pyplot as plt
>>> x = np.arange(-5, 5, 0.1)
>>> y = np.arange(-5, 5, 0.1)
>>> xx, yy = np.meshgrid(x, y, sparse=True)
>>> z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
>>> h = plt.contourf(x,y,z)
>>> plt.show()