diff options
-rw-r--r-- | numpy/core/numeric.py | 13 | ||||
-rw-r--r-- | numpy/core/tests/test_shape_base.py | 4 | ||||
-rw-r--r-- | numpy/lib/function_base.py | 14 | ||||
-rw-r--r-- | numpy/lib/nanfunctions.py | 2 | ||||
-rw-r--r-- | numpy/lib/tests/test_function_base.py | 4 | ||||
-rw-r--r-- | numpy/lib/utils.py | 2 | ||||
-rw-r--r-- | numpy/linalg/linalg.py | 6 | ||||
-rw-r--r-- | numpy/polynomial/chebyshev.py | 10 | ||||
-rw-r--r-- | numpy/polynomial/hermite.py | 10 | ||||
-rw-r--r-- | numpy/polynomial/hermite_e.py | 10 | ||||
-rw-r--r-- | numpy/polynomial/laguerre.py | 10 | ||||
-rw-r--r-- | numpy/polynomial/legendre.py | 10 | ||||
-rw-r--r-- | numpy/polynomial/polynomial.py | 10 |
13 files changed, 53 insertions, 52 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 7d53f2b68..e9bb39ad4 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1435,6 +1435,10 @@ def rollaxis(a, axis, start=0): """ Roll the specified axis backwards, until it lies in a given position. + This function continues to be supported for backward compatibility, but you + should prefer `moveaxis`. The `moveaxis` function was added in NumPy + 1.11. + Parameters ---------- a : ndarray @@ -1617,7 +1621,7 @@ def moveaxis(a, source, destination): # fix hack in scipy which imports this function def _move_axis_to_0(a, axis): - return rollaxis(a, axis, 0) + return moveaxis(a, axis, 0) def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None): @@ -1742,8 +1746,8 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None): axisb = normalize_axis_index(axisb, b.ndim, msg_prefix='axisb') # Move working axis to the end of the shape - a = rollaxis(a, axisa, a.ndim) - b = rollaxis(b, axisb, b.ndim) + a = moveaxis(a, axisa, -1) + b = moveaxis(b, axisb, -1) msg = ("incompatible dimensions for cross product\n" "(dimension must be 2 or 3)") if a.shape[-1] not in (2, 3) or b.shape[-1] not in (2, 3): @@ -1814,8 +1818,7 @@ def cross(a, b, axisa=-1, axisb=-1, axisc=-1, axis=None): multiply(a0, b1, out=cp2) cp2 -= a1 * b0 - # This works because we are moving the last axis - return rollaxis(cp, -1, axisc) + return moveaxis(cp, -1, axisc) # Use numarray's printing function diff --git a/numpy/core/tests/test_shape_base.py b/numpy/core/tests/test_shape_base.py index 9913af67a..d1fbe8e92 100644 --- a/numpy/core/tests/test_shape_base.py +++ b/numpy/core/tests/test_shape_base.py @@ -208,8 +208,8 @@ class TestConcatenate(object): np.concatenate((a, b), axis=axis[0]) # OK assert_raises(ValueError, np.concatenate, (a, b), axis=axis[1]) assert_raises(ValueError, np.concatenate, (a, b), axis=axis[2]) - a = np.rollaxis(a, -1) - b = np.rollaxis(b, -1) + a = np.moveaxis(a, -1, 0) + b = np.moveaxis(b, -1, 0) axis.append(axis.pop(0)) # No arrays to concatenate raises ValueError diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index c185f9639..b1ebcad67 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -4336,7 +4336,7 @@ def _percentile(a, q, axis=None, out=None, ap.partition(indices, axis=axis) # ensure axis with qth is first - ap = np.rollaxis(ap, axis, 0) + ap = np.moveaxis(ap, axis, 0) axis = 0 # Check if the array contains any nan's @@ -4369,9 +4369,9 @@ def _percentile(a, q, axis=None, out=None, ap.partition(concatenate((indices_below, indices_above)), axis=axis) # ensure axis with qth is first - ap = np.rollaxis(ap, axis, 0) - weights_below = np.rollaxis(weights_below, axis, 0) - weights_above = np.rollaxis(weights_above, axis, 0) + ap = np.moveaxis(ap, axis, 0) + weights_below = np.moveaxis(weights_below, axis, 0) + weights_above = np.moveaxis(weights_above, axis, 0) axis = 0 # Check if the array contains any nan's @@ -4383,8 +4383,8 @@ def _percentile(a, q, axis=None, out=None, x2 = take(ap, indices_above, axis=axis) * weights_above # ensure axis with qth is first - x1 = np.rollaxis(x1, axis, 0) - x2 = np.rollaxis(x2, axis, 0) + x1 = np.moveaxis(x1, axis, 0) + x2 = np.moveaxis(x2, axis, 0) if zerod: x1 = x1.squeeze(0) @@ -5040,7 +5040,7 @@ def insert(arr, obj, values, axis=None): # broadcasting is very different here, since a[:,0,:] = ... behaves # very different from a[:,[0],:] = ...! This changes values so that # it works likes the second case. (here a[:,0:1,:]) - values = np.rollaxis(values, 0, (axis % values.ndim) + 1) + values = np.moveaxis(values, 0, axis) numnew = values.shape[axis] newshape[axis] += numnew new = empty(newshape, arr.dtype, arrorder) diff --git a/numpy/lib/nanfunctions.py b/numpy/lib/nanfunctions.py index 90120719e..79bf01281 100644 --- a/numpy/lib/nanfunctions.py +++ b/numpy/lib/nanfunctions.py @@ -1174,7 +1174,7 @@ def _nanpercentile(a, q, axis=None, out=None, overwrite_input=False, # Move that axis to the beginning to match percentile's # convention. if q.ndim != 0: - result = np.rollaxis(result, axis) + result = np.moveaxis(result, axis, 0) if out is not None: out[...] = result diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 151c20a4b..4c90abbf6 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -3011,7 +3011,7 @@ class TestPercentile(object): o = np.random.normal(size=(71, 23)) x = np.dstack([o] * 10) assert_equal(np.percentile(x, 30, axis=(0, 1)), np.percentile(o, 30)) - x = np.rollaxis(x, -1, 0) + x = np.moveaxis(x, -1, 0) assert_equal(np.percentile(x, 30, axis=(-2, -1)), np.percentile(o, 30)) x = x.swapaxes(0, 1).copy() assert_equal(np.percentile(x, 30, axis=(0, -1)), np.percentile(o, 30)) @@ -3392,7 +3392,7 @@ class TestMedian(object): o = np.random.normal(size=(71, 23)) x = np.dstack([o] * 10) assert_equal(np.median(x, axis=(0, 1)), np.median(o)) - x = np.rollaxis(x, -1, 0) + x = np.moveaxis(x, -1, 0) assert_equal(np.median(x, axis=(-2, -1)), np.median(o)) x = x.swapaxes(0, 1).copy() assert_equal(np.median(x, axis=(0, -1)), np.median(o)) diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index 6e150add3..e18eda0fb 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -1138,7 +1138,7 @@ def _median_nancheck(data, result, axis, out): """ if data.size == 0: return result - data = np.rollaxis(data, axis, data.ndim) + data = np.moveaxis(data, axis, -1) n = np.isnan(data[..., -1]) # masked NaN values are ok if np.ma.isMaskedArray(n): diff --git a/numpy/linalg/linalg.py b/numpy/linalg/linalg.py index cd8999785..dd5ac6255 100644 --- a/numpy/linalg/linalg.py +++ b/numpy/linalg/linalg.py @@ -22,7 +22,7 @@ from numpy.core import ( array, asarray, zeros, empty, empty_like, transpose, intc, single, double, csingle, cdouble, inexact, complexfloating, newaxis, ravel, all, Inf, dot, add, multiply, sqrt, maximum, fastCopyAndTranspose, sum, isfinite, size, - finfo, errstate, geterrobj, longdouble, rollaxis, amin, amax, product, abs, + finfo, errstate, geterrobj, longdouble, moveaxis, amin, amax, product, abs, broadcast, atleast_2d, intp, asanyarray, isscalar, object_, ones ) from numpy.core.multiarray import normalize_axis_index @@ -2004,9 +2004,7 @@ def _multi_svd_norm(x, row_axis, col_axis, op): is `numpy.amin` or `numpy.amax` or `numpy.sum`. """ - if row_axis > col_axis: - row_axis -= 1 - y = rollaxis(rollaxis(x, col_axis, x.ndim), row_axis, -1) + y = moveaxis(x, (row_axis, col_axis), (-2, -1)) result = op(svd(y, compute_uv=0), axis=-1) return result diff --git a/numpy/polynomial/chebyshev.py b/numpy/polynomial/chebyshev.py index b28ea0462..eb9797e0f 100644 --- a/numpy/polynomial/chebyshev.py +++ b/numpy/polynomial/chebyshev.py @@ -944,7 +944,7 @@ def chebder(c, m=1, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) n = len(c) if cnt >= n: c = c[:1]*0 @@ -960,7 +960,7 @@ def chebder(c, m=1, scl=1, axis=0): der[1] = 4*c[2] der[0] = c[1] c = der - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -1069,7 +1069,7 @@ def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) k = list(k) + [0]*(cnt - len(k)) for i in range(cnt): n = len(c) @@ -1088,7 +1088,7 @@ def chebint(c, m=1, k=[], lbnd=0, scl=1, axis=0): tmp[j - 1] -= c[j]/(2*(j - 1)) tmp[0] += k[i] - chebval(lbnd, tmp) c = tmp - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -1460,7 +1460,7 @@ def chebvander(x, deg): v[1] = x for i in range(2, ideg + 1): v[i] = v[i-1]*x2 - v[i-2] - return np.rollaxis(v, 0, v.ndim) + return np.moveaxis(v, 0, -1) def chebvander2d(x, y, deg): diff --git a/numpy/polynomial/hermite.py b/numpy/polynomial/hermite.py index ccf0fc146..856ac487e 100644 --- a/numpy/polynomial/hermite.py +++ b/numpy/polynomial/hermite.py @@ -706,7 +706,7 @@ def hermder(c, m=1, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) n = len(c) if cnt >= n: c = c[:1]*0 @@ -718,7 +718,7 @@ def hermder(c, m=1, scl=1, axis=0): for j in range(n, 0, -1): der[j - 1] = (2*j)*c[j] c = der - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -825,7 +825,7 @@ def hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) k = list(k) + [0]*(cnt - len(k)) for i in range(cnt): n = len(c) @@ -840,7 +840,7 @@ def hermint(c, m=1, k=[], lbnd=0, scl=1, axis=0): tmp[j + 1] = c[j]/(2*(j + 1)) tmp[0] += k[i] - hermval(lbnd, tmp) c = tmp - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -1229,7 +1229,7 @@ def hermvander(x, deg): v[1] = x2 for i in range(2, ideg + 1): v[i] = (v[i-1]*x2 - v[i-2]*(2*(i - 1))) - return np.rollaxis(v, 0, v.ndim) + return np.moveaxis(v, 0, -1) def hermvander2d(x, y, deg): diff --git a/numpy/polynomial/hermite_e.py b/numpy/polynomial/hermite_e.py index 2fafea4af..e83b26327 100644 --- a/numpy/polynomial/hermite_e.py +++ b/numpy/polynomial/hermite_e.py @@ -705,7 +705,7 @@ def hermeder(c, m=1, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) n = len(c) if cnt >= n: return c[:1]*0 @@ -717,7 +717,7 @@ def hermeder(c, m=1, scl=1, axis=0): for j in range(n, 0, -1): der[j - 1] = j*c[j] c = der - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -824,7 +824,7 @@ def hermeint(c, m=1, k=[], lbnd=0, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) k = list(k) + [0]*(cnt - len(k)) for i in range(cnt): n = len(c) @@ -839,7 +839,7 @@ def hermeint(c, m=1, k=[], lbnd=0, scl=1, axis=0): tmp[j + 1] = c[j]/(j + 1) tmp[0] += k[i] - hermeval(lbnd, tmp) c = tmp - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -1226,7 +1226,7 @@ def hermevander(x, deg): v[1] = x for i in range(2, ideg + 1): v[i] = (v[i-1]*x - v[i-2]*(i - 1)) - return np.rollaxis(v, 0, v.ndim) + return np.moveaxis(v, 0, -1) def hermevander2d(x, y, deg): diff --git a/numpy/polynomial/laguerre.py b/numpy/polynomial/laguerre.py index 387d986fa..60373b8c8 100644 --- a/numpy/polynomial/laguerre.py +++ b/numpy/polynomial/laguerre.py @@ -703,7 +703,7 @@ def lagder(c, m=1, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) n = len(c) if cnt >= n: c = c[:1]*0 @@ -717,7 +717,7 @@ def lagder(c, m=1, scl=1, axis=0): c[j - 1] += c[j] der[0] = -c[1] c = der - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -825,7 +825,7 @@ def lagint(c, m=1, k=[], lbnd=0, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) k = list(k) + [0]*(cnt - len(k)) for i in range(cnt): n = len(c) @@ -841,7 +841,7 @@ def lagint(c, m=1, k=[], lbnd=0, scl=1, axis=0): tmp[j + 1] = -c[j] tmp[0] += k[i] - lagval(lbnd, tmp) c = tmp - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -1228,7 +1228,7 @@ def lagvander(x, deg): v[1] = 1 - x for i in range(2, ideg + 1): v[i] = (v[i-1]*(2*i - 1 - x) - v[i-2]*(i - 1))/i - return np.rollaxis(v, 0, v.ndim) + return np.moveaxis(v, 0, -1) def lagvander2d(x, y, deg): diff --git a/numpy/polynomial/legendre.py b/numpy/polynomial/legendre.py index d4b4dd130..5128643cd 100644 --- a/numpy/polynomial/legendre.py +++ b/numpy/polynomial/legendre.py @@ -742,7 +742,7 @@ def legder(c, m=1, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) n = len(c) if cnt >= n: c = c[:1]*0 @@ -758,7 +758,7 @@ def legder(c, m=1, scl=1, axis=0): der[1] = 3*c[2] der[0] = c[1] c = der - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -867,7 +867,7 @@ def legint(c, m=1, k=[], lbnd=0, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) k = list(k) + [0]*(cnt - len(k)) for i in range(cnt): n = len(c) @@ -886,7 +886,7 @@ def legint(c, m=1, k=[], lbnd=0, scl=1, axis=0): tmp[j - 1] -= t tmp[0] += k[i] - legval(lbnd, tmp) c = tmp - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -1259,7 +1259,7 @@ def legvander(x, deg): v[1] = x for i in range(2, ideg + 1): v[i] = (v[i-1]*x*(2*i - 1) - v[i-2]*(i - 1))/i - return np.rollaxis(v, 0, v.ndim) + return np.moveaxis(v, 0, -1) def legvander2d(x, y, deg): diff --git a/numpy/polynomial/polynomial.py b/numpy/polynomial/polynomial.py index 4b343bf7d..1528de342 100644 --- a/numpy/polynomial/polynomial.py +++ b/numpy/polynomial/polynomial.py @@ -546,7 +546,7 @@ def polyder(c, m=1, scl=1, axis=0): if cnt == 0: return c - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) n = len(c) if cnt >= n: c = c[:1]*0 @@ -558,7 +558,7 @@ def polyder(c, m=1, scl=1, axis=0): for j in range(n, 0, -1): der[j - 1] = j*c[j] c = der - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -662,7 +662,7 @@ def polyint(c, m=1, k=[], lbnd=0, scl=1, axis=0): return c k = list(k) + [0]*(cnt - len(k)) - c = np.rollaxis(c, iaxis) + c = np.moveaxis(c, iaxis, 0) for i in range(cnt): n = len(c) c *= scl @@ -676,7 +676,7 @@ def polyint(c, m=1, k=[], lbnd=0, scl=1, axis=0): tmp[j + 1] = c[j]/(j + 1) tmp[0] += k[i] - polyval(lbnd, tmp) c = tmp - c = np.rollaxis(c, 0, iaxis + 1) + c = np.moveaxis(c, 0, iaxis) return c @@ -1147,7 +1147,7 @@ def polyvander(x, deg): v[1] = x for i in range(2, ideg + 1): v[i] = v[i-1]*x - return np.rollaxis(v, 0, v.ndim) + return np.moveaxis(v, 0, -1) def polyvander2d(x, y, deg): |