diff options
author | Ralf Gommers <ralf.gommers@googlemail.com> | 2011-12-28 10:30:08 +0100 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@googlemail.com> | 2011-12-28 10:30:08 +0100 |
commit | 3fb541ef51ca60cf5a903ed83f69120fe3f5373a (patch) | |
tree | 43edfe4f0c61db86a0471844f0d55ab119789842 /numpy/lib/function_base.py | |
parent | 4e571172a210612bdeba1db0135b7d5fbc44ee0c (diff) | |
download | numpy-3fb541ef51ca60cf5a903ed83f69120fe3f5373a.tar.gz |
TST: meshgrid: test expected shapes for Cartesian and matrix indexing.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 8e2fc375e..39d1d1c87 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -3215,6 +3215,7 @@ def meshgrid(*xi, **kwargs): 1-D arrays representing the coordinates of a grid. indexing : {'xy', 'ij'}, optional Cartesian ('xy', default) or matrix ('ij') indexing of output. + See Notes for more details. sparse : bool, optional If True a sparse grid is returned in order to conserve memory. Default is False. @@ -3238,9 +3239,13 @@ def meshgrid(*xi, **kwargs): Notes ----- 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. The difference is - illustrated by the following code snippet:: + 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 = meshgrid(x, y, sparse=False, indexing='ij') for i in range(nx): @@ -3287,8 +3292,6 @@ def meshgrid(*xi, **kwargs): >>> h = plt.contourf(x,y,z) """ - copy_ = kwargs.get('copy', True) - if len(xi) < 2: msg = 'meshgrid() takes 2 or more arguments (%d given)' % int(len(xi) > 0) raise ValueError(msg) @@ -3296,8 +3299,11 @@ def meshgrid(*xi, **kwargs): args = np.atleast_1d(*xi) ndim = len(args) + copy_ = kwargs.get('copy', True) sparse = kwargs.get('sparse', False) indexing = kwargs.get('indexing', 'xy') + if not indexing in ['xy', 'ij']: + raise ValueError("Valid values for `indexing` are 'xy' and 'ij'.") s0 = (1,) * ndim output = [x.reshape(s0[:i] + (-1,) + s0[i + 1::]) for i, x in enumerate(args)] |