diff options
author | Eric Wieser <wieser.eric@gmail.com> | 2017-02-13 21:02:06 +0000 |
---|---|---|
committer | Eric Wieser <wieser.eric@gmail.com> | 2017-02-13 21:09:04 +0000 |
commit | d932fcd38d9ef0f76c988d6c197856fa0c71314b (patch) | |
tree | 5ef0d0caa7daedc7759c18fb5cd8d78ef46fec58 /numpy/lib/function_base.py | |
parent | ee40ff69127fee94e7e3103445729024e7b3de21 (diff) | |
download | numpy-d932fcd38d9ef0f76c988d6c197856fa0c71314b.tar.gz |
BUG: Copy meshgrid after broadcasting, fixing #8561
Also, remove some unused variables
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 51353351f..23f8d7d4d 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -4498,24 +4498,21 @@ def meshgrid(*xi, **kwargs): "Valid values for `indexing` are 'xy' and 'ij'.") s0 = (1,) * ndim - output = [np.asanyarray(x).reshape(s0[:i] + (-1,) + s0[i + 1::]) + output = [np.asanyarray(x).reshape(s0[:i] + (-1,) + s0[i + 1:]) for i, x in enumerate(xi)] - shape = [x.size for x in output] - if indexing == 'xy' and ndim > 1: # switch first and second axis - output[0].shape = (1, -1) + (1,)*(ndim - 2) - output[1].shape = (-1, 1) + (1,)*(ndim - 2) - shape[0], shape[1] = shape[1], shape[0] - - if copy_: - output = [x.copy() for x in output] + output[0].shape = (1, -1) + s0[2:] + output[1].shape = (-1, 1) + s0[2:] - if not sparse and len(output) > 0: + if not sparse: # Return the full N-D matrix (not only the 1-D vector) output = np.broadcast_arrays(*output, subok=True) + if copy_: + output = [x.copy() for x in output] + return output |