summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorMarten van Kerkwijk <mhvk@astro.utoronto.ca>2017-02-14 14:33:08 -0500
committerGitHub <noreply@github.com>2017-02-14 14:33:08 -0500
commit9106adfba085e93bf066d47e2da47b47839c8e08 (patch)
treec85bdb8fa5df6422bdb575c77372be7ae87cf6ae /numpy/lib/function_base.py
parentbbd5a7750fbed42a4aaf12f196282a9504a1e865 (diff)
parentd9b26f804117ebc1f591dff33d06ce2339af9339 (diff)
downloadnumpy-9106adfba085e93bf066d47e2da47b47839c8e08.tar.gz
Merge pull request #8617 from eric-wieser/fix-8561
BUG: Copy meshgrid after broadcasting
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py17
1 files changed, 7 insertions, 10 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 2aa104174..ae1420b72 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -4505,24 +4505,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