Return a list of 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. .. versionchanged:: 1.9 1-D and 0-D cases are allowed.
(*xi, copy=True, sparse=False, indexing='xy')
| 5010 | # Based on scitools meshgrid |
| 5011 | @array_function_dispatch(_meshgrid_dispatcher) |
| 5012 | def meshgrid(*xi, copy=True, sparse=False, indexing='xy'): |
| 5013 | """ |
| 5014 | Return a list of coordinate matrices from coordinate vectors. |
| 5015 | |
| 5016 | Make N-D coordinate arrays for vectorized evaluations of |
| 5017 | N-D scalar/vector fields over N-D grids, given |
| 5018 | one-dimensional coordinate arrays x1, x2,..., xn. |
| 5019 | |
| 5020 | .. versionchanged:: 1.9 |
| 5021 | 1-D and 0-D cases are allowed. |
| 5022 | |
| 5023 | Parameters |
| 5024 | ---------- |
| 5025 | x1, x2,..., xn : array_like |
| 5026 | 1-D arrays representing the coordinates of a grid. |
| 5027 | indexing : {'xy', 'ij'}, optional |
| 5028 | Cartesian ('xy', default) or matrix ('ij') indexing of output. |
| 5029 | See Notes for more details. |
| 5030 | |
| 5031 | .. versionadded:: 1.7.0 |
| 5032 | sparse : bool, optional |
| 5033 | If True the shape of the returned coordinate array for dimension *i* |
| 5034 | is reduced from ``(N1, ..., Ni, ... Nn)`` to |
| 5035 | ``(1, ..., 1, Ni, 1, ..., 1)``. These sparse coordinate grids are |
| 5036 | intended to be use with :ref:`basics.broadcasting`. When all |
| 5037 | coordinates are used in an expression, broadcasting still leads to a |
| 5038 | fully-dimensonal result array. |
| 5039 | |
| 5040 | Default is False. |
| 5041 | |
| 5042 | .. versionadded:: 1.7.0 |
| 5043 | copy : bool, optional |
| 5044 | If False, a view into the original arrays are returned in order to |
| 5045 | conserve memory. Default is True. Please note that |
| 5046 | ``sparse=False, copy=False`` will likely return non-contiguous |
| 5047 | arrays. Furthermore, more than one element of a broadcast array |
| 5048 | may refer to a single memory location. If you need to write to the |
| 5049 | arrays, make copies first. |
| 5050 | |
| 5051 | .. versionadded:: 1.7.0 |
| 5052 | |
| 5053 | Returns |
| 5054 | ------- |
| 5055 | X1, X2,..., XN : list of ndarrays |
| 5056 | For vectors `x1`, `x2`,..., `xn` with lengths ``Ni=len(xi)``, |
| 5057 | returns ``(N1, N2, N3,..., Nn)`` shaped arrays if indexing='ij' |
| 5058 | or ``(N2, N1, N3,..., Nn)`` shaped arrays if indexing='xy' |
| 5059 | with the elements of `xi` repeated to fill the matrix along |
| 5060 | the first dimension for `x1`, the second for `x2` and so on. |
| 5061 | |
| 5062 | Notes |
| 5063 | ----- |
| 5064 | This function supports both indexing conventions through the indexing |
| 5065 | keyword argument. Giving the string 'ij' returns a meshgrid with |
| 5066 | matrix indexing, while 'xy' returns a meshgrid with Cartesian indexing. |
| 5067 | In the 2-D case with inputs of length M and N, the outputs are of shape |
| 5068 | (N, M) for 'xy' indexing and (M, N) for 'ij' indexing. In the 3-D case |
| 5069 | with inputs of length M, N and P, outputs are of shape (N, M, P) for |