MCPcopy Index your code
hub / github.com/numpy/numpy / meshgrid

Function meshgrid

numpy/lib/_function_base_impl.py:5063–5213  ·  view source on GitHub ↗

Return a tuple 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. Parameters ---------- x1, x2,..., xn : array_like

(*xi, copy=True, sparse=False, indexing='xy')

Source from the content-addressed store, hash-verified

5061# Based on scitools meshgrid
5062@array_function_dispatch(_meshgrid_dispatcher)
5063def meshgrid(*xi, copy=True, sparse=False, indexing='xy'):
5064 """
5065 Return a tuple of coordinate matrices from coordinate vectors.
5066
5067 Make N-D coordinate arrays for vectorized evaluations of
5068 N-D scalar/vector fields over N-D grids, given
5069 one-dimensional coordinate arrays x1, x2,..., xn.
5070
5071 Parameters
5072 ----------
5073 x1, x2,..., xn : array_like
5074 1-D arrays representing the coordinates of a grid.
5075 indexing : {'xy', 'ij'}, optional
5076 Cartesian ('xy', default) or matrix ('ij') indexing of output.
5077 See Notes for more details.
5078 sparse : bool, optional
5079 If True the shape of the returned coordinate array for dimension *i*
5080 is reduced from ``(N1, ..., Ni, ... Nn)`` to
5081 ``(1, ..., 1, Ni, 1, ..., 1)``. These sparse coordinate grids are
5082 intended to be used with :ref:`basics.broadcasting`. When all
5083 coordinates are used in an expression, broadcasting still leads to a
5084 fully-dimensional result array.
5085
5086 Default is False.
5087
5088 copy : bool, optional
5089 If False, a view into the original arrays are returned in order to
5090 conserve memory. Default is True. Please note that
5091 ``sparse=False, copy=False`` will likely return non-contiguous
5092 arrays. Furthermore, more than one element of a broadcast array
5093 may refer to a single memory location. If you need to write to the
5094 arrays, make copies first.
5095
5096 Returns
5097 -------
5098 X1, X2,..., XN : tuple of ndarrays
5099 For vectors `x1`, `x2`,..., `xn` with lengths ``Ni=len(xi)``,
5100 returns ``(N1, N2, N3,..., Nn)`` shaped arrays if indexing='ij'
5101 or ``(N2, N1, N3,..., Nn)`` shaped arrays if indexing='xy'
5102 with the elements of `xi` repeated to fill the matrix along
5103 the first dimension for `x1`, the second for `x2` and so on.
5104
5105 Notes
5106 -----
5107 This function supports both indexing conventions through the indexing
5108 keyword argument. Giving the string 'ij' returns a meshgrid with
5109 matrix indexing, while 'xy' returns a meshgrid with Cartesian indexing.
5110 In the 2-D case with inputs of length M and N, the outputs are of shape
5111 (N, M) for 'xy' indexing and (M, N) for 'ij' indexing. In the 3-D case
5112 with inputs of length M, N and P, outputs are of shape (N, M, P) for
5113 'xy' indexing and (M, N, P) for 'ij' indexing. The difference is
5114 illustrated by the following code snippet::
5115
5116 xv, yv = np.meshgrid(x, y, indexing='ij')
5117 for i in range(nx):
5118 for j in range(ny):
5119 # treat xv[i,j], yv[i,j]
5120

Callers 6

test_simpleMethod · 0.90
test_single_inputMethod · 0.90
test_no_inputMethod · 0.90
test_indexingMethod · 0.90
test_sparseMethod · 0.90
test_always_tupleMethod · 0.90

Calls 2

reshapeMethod · 0.80
copyMethod · 0.45

Tested by 6

test_simpleMethod · 0.72
test_single_inputMethod · 0.72
test_no_inputMethod · 0.72
test_indexingMethod · 0.72
test_sparseMethod · 0.72
test_always_tupleMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…