summaryrefslogtreecommitdiff
path: root/numpy/core/numeric.py
diff options
context:
space:
mode:
authorJaime <jaime.frio@gmail.com>2015-01-19 09:10:22 -0800
committerJaime <jaime.frio@gmail.com>2015-01-19 09:10:22 -0800
commit4ed1587a7de85b4fa01dff8ef6e0e901a25f149c (patch)
tree74083e9a2a04521596d8c42b016482512d516f28 /numpy/core/numeric.py
parent8a81c08e777996b933fe4568ee5a6a0e01416faf (diff)
parentcf41fceb22df5e6f2f48108a4beb4325e5f8b7fa (diff)
downloadnumpy-4ed1587a7de85b4fa01dff8ef6e0e901a25f149c.tar.gz
Merge pull request #5464 from charris/rollaxis-always-return-view
Rollaxis always return view
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r--numpy/core/numeric.py17
1 files changed, 11 insertions, 6 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py
index 430f7a715..a464562c4 100644
--- a/numpy/core/numeric.py
+++ b/numpy/core/numeric.py
@@ -1392,6 +1392,7 @@ def roll(a, shift, axis=None):
res = res.reshape(a.shape)
return res
+
def rollaxis(a, axis, start=0):
"""
Roll the specified axis backwards, until it lies in a given position.
@@ -1410,7 +1411,9 @@ def rollaxis(a, axis, start=0):
Returns
-------
res : ndarray
- Output array.
+ For Numpy >= 1.10 a view of `a` is always returned. For earlier
+ Numpy versions a view of `a` is returned only if the order of the
+ axes is changed, otherwise the input array is returned.
See Also
--------
@@ -1436,17 +1439,19 @@ def rollaxis(a, axis, start=0):
msg = 'rollaxis: %s (%d) must be >=0 and < %d'
if not (0 <= axis < n):
raise ValueError(msg % ('axis', axis, n))
- if not (0 <= start < n+1):
- raise ValueError(msg % ('start', start, n+1))
- if (axis < start): # it's been removed
+ if not (0 <= start < n + 1):
+ raise ValueError(msg % ('start', start, n + 1))
+ if (axis < start):
+ # it's been removed
start -= 1
- if axis==start:
- return a
+ if axis == start:
+ return a[...]
axes = list(range(0, n))
axes.remove(axis)
axes.insert(start, axis)
return a.transpose(axes)
+
# fix hack in scipy which imports this function
def _move_axis_to_0(a, axis):
return rollaxis(a, axis, 0)