meshgrid(*xi, **kwargs)
This docstring was copied from numpy.meshgrid.
Some inconsistencies with the Dask version may exist.
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.
1-D and 0-D cases are allowed.
This function supports both indexing conventions through the indexing keyword argument. Giving the string 'ij' returns a meshgrid with matrix indexing, while 'xy' returns a meshgrid with Cartesian indexing. In the 2-D case with inputs of length M and N, the outputs are of shape (N, M) for 'xy' indexing and (M, N) for 'ij' indexing. In the 3-D case with inputs of length M, N and P, outputs are of shape (N, M, P) for 'xy' indexing and (M, N, P) for 'ij' indexing. The difference is illustrated by the following code snippet:
xv, yv = np.meshgrid(x, y, indexing='ij') for i in range(nx): for j in range(ny): # treat xv[i,j], yv[i,j] xv, yv = np.meshgrid(x, y, indexing='xy') for i in range(nx): for j in range(ny): # treat xv[j,i], yv[j,i]
In the 1-D and 0-D case, the indexing and sparse keywords have no effect.
1-D arrays representing the coordinates of a grid.
Cartesian ('xy', default) or matrix ('ij') indexing of output. See Notes for more details.
If True the shape of the returned coordinate array for dimension i is reduced from (N1, ..., Ni, ... Nn)
to (1, ..., 1, Ni, 1, ..., 1)
. These sparse coordinate grids are intended to be use with basics.broadcasting
. When all coordinates are used in an expression, broadcasting still leads to a fully-dimensonal result array.
Default is False.
If False, a view into the original arrays are returned in order to conserve memory. Default is True. Please note that sparse=False, copy=False
will likely return non-contiguous arrays. Furthermore, more than one element of a broadcast array may refer to a single memory location. If you need to write to the arrays, make copies first.
For vectors :None:None:`x1`
, :None:None:`x2`
,..., 'xn' with lengths Ni=len(xi)
, return (N1, N2, N3,...Nn)
shaped arrays if indexing='ij' or (N2, N1, N3,...Nn)
shaped arrays if indexing='xy' with the elements of :None:None:`xi`
repeated to fill the matrix along the first dimension for :None:None:`x1`
, the second for :None:None:`x2`
and so on.
Return coordinate matrices from coordinate vectors.
mgrid
Construct a multi-dimensional "meshgrid" using indexing notation.
ogrid
Construct an open multi-dimensional "meshgrid" using indexing notation.
>>> nx, ny = (3, 2) # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... x = np.linspace(0, 1, nx) # doctest: +SKIP
... y = np.linspace(0, 1, ny) # doctest: +SKIP
... xv, yv = np.meshgrid(x, y) # doctest: +SKIP
... xv # doctest: +SKIP array([[0. , 0.5, 1. ], [0. , 0.5, 1. ]])
>>> yv # doctest: +SKIP array([[0., 0., 0.], [1., 1., 1.]])This example is valid syntax, but we were not able to check execution
>>> xv, yv = np.meshgrid(x, y, sparse=True) # make sparse output arrays # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... xv # doctest: +SKIP array([[0. , 0.5, 1. ]])
>>> yv # doctest: +SKIP array([[0.], [1.]])
meshgrid
is very useful to evaluate functions on a grid. If the function depends on all coordinates, you can use the parameter sparse=True
to save memory and computation time.
>>> x = np.linspace(-5, 5, 101) # doctest: +SKIPThis example is valid syntax, but we were not able to check execution
... y = np.linspace(-5, 5, 101) # doctest: +SKIP
... # full coorindate arrays
... xx, yy = np.meshgrid(x, y) # doctest: +SKIP
... zz = np.sqrt(xx**2 + yy**2) # doctest: +SKIP
... xx.shape, yy.shape, zz.shape # doctest: +SKIP ((101, 101), (101, 101), (101, 101))
>>> # sparse coordinate arraysThis example is valid syntax, but we were not able to check execution
... xs, ys = np.meshgrid(x, y, sparse=True) # doctest: +SKIP
... zs = np.sqrt(xs**2 + ys**2) # doctest: +SKIP
... xs.shape, ys.shape, zs.shape # doctest: +SKIP ((1, 101), (101, 1), (101, 101))
>>> np.array_equal(zz, zs) # doctest: +SKIP TrueThis example is valid syntax, but we were not able to check execution
>>> import matplotlib.pyplot as plt # doctest: +SKIPSee :
... h = plt.contourf(x, y, zs) # doctest: +SKIP
... plt.axis('scaled') # doctest: +SKIP
... plt.colorbar() # doctest: +SKIP
... plt.show() # doctest: +SKIP
The following pages refer to to this document either explicitly or contain code examples using this.
dask.array.creation.meshgrid
dask.array.creation.fromfunction
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them