summaryrefslogtreecommitdiff
path: root/numpy/lib/shape_base.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-01-03 00:56:10 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-02-11 21:09:09 +0000
commit9f362bfb3f99c0bcb30e9bd6e568e40ae5a0cf7b (patch)
treefdc72ba99dca4388e1c45aeb5f217c86928a2f65 /numpy/lib/shape_base.py
parentb10b6c290ded55e410543b9d09686042be3db6ec (diff)
downloadnumpy-9f362bfb3f99c0bcb30e9bd6e568e40ae5a0cf7b.tar.gz
BUG: Work around evil matrix.__array_prepare__
Diffstat (limited to 'numpy/lib/shape_base.py')
-rw-r--r--numpy/lib/shape_base.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index 7e70904b1..120153ad5 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -9,6 +9,7 @@ from numpy.core.numeric import (
from numpy.core.fromnumeric import product, reshape, transpose
from numpy.core import vstack, atleast_3d
from numpy.lib.index_tricks import ndindex
+from numpy.matrixlib.defmatrix import matrix # this raises all the right alarm bells
__all__ = [
@@ -116,7 +117,11 @@ def apply_along_axis(func1d, axis, arr, *args, **kwargs):
# insert as many axes as necessary to create the output
outshape = arr.shape[:axis] + res.shape + arr.shape[axis+1:]
outarr = zeros(outshape, res.dtype)
- outarr = res.__array_prepare__(outarr)
+ # matrices call reshape in __array_prepare__, and this is apparently ok!
+ if not isinstance(res, matrix):
+ outarr = res.__array_prepare__(outarr)
+ if outshape != outarr.shape:
+ raise ValueError('__array_prepare__ should not change the shape of the resultant array')
# outarr, with inserted dimensions at the end
# this means that outarr_view[i] = func1d(inarr_view[i])