summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2017-02-24 16:46:58 +0000
committerEric Wieser <wieser.eric@gmail.com>2017-02-24 16:46:58 +0000
commit48783e5ceb7f60c33db81ab72e5024f42b220990 (patch)
tree2284b780e521418b0e73fd7283403d3e7e28da50 /numpy/lib
parent5f5ccecbfc116284ed8c8d53cd8b203ceef5f7c7 (diff)
downloadnumpy-48783e5ceb7f60c33db81ab72e5024f42b220990.tar.gz
MAINT: replace len(x.shape) with x.ndim
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/arraypad.py2
-rw-r--r--numpy/lib/arrayterator.py4
-rw-r--r--numpy/lib/function_base.py8
-rw-r--r--numpy/lib/npyio.py2
-rw-r--r--numpy/lib/polynomial.py4
-rw-r--r--numpy/lib/shape_base.py10
-rw-r--r--numpy/lib/user_array.py4
7 files changed, 17 insertions, 17 deletions
diff --git a/numpy/lib/arraypad.py b/numpy/lib/arraypad.py
index 15e3ed957..2dad99c34 100644
--- a/numpy/lib/arraypad.py
+++ b/numpy/lib/arraypad.py
@@ -1338,7 +1338,7 @@ def pad(array, pad_width, mode, **kwargs):
function = mode
# Create a new padded array
- rank = list(range(len(narray.shape)))
+ rank = list(range(narray.ndim))
total_dim_increase = [np.sum(pad_width[i]) for i in rank]
offset_slices = [slice(pad_width[i][0],
pad_width[i][0] + narray.shape[i])
diff --git a/numpy/lib/arrayterator.py b/numpy/lib/arrayterator.py
index fb52ada86..f2d4fe9fd 100644
--- a/numpy/lib/arrayterator.py
+++ b/numpy/lib/arrayterator.py
@@ -106,7 +106,7 @@ class Arrayterator(object):
if not isinstance(index, tuple):
index = (index,)
fixed = []
- length, dims = len(index), len(self.shape)
+ length, dims = len(index), self.ndim
for slice_ in index:
if slice_ is Ellipsis:
fixed.extend([slice(None)] * (dims-length+1))
@@ -186,7 +186,7 @@ class Arrayterator(object):
start = self.start[:]
stop = self.stop[:]
step = self.step[:]
- ndims = len(self.var.shape)
+ ndims = self.var.ndim
while True:
count = self.buf_size or reduce(mul, self.shape)
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index fc49a6fd7..1cf57d617 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1674,7 +1674,7 @@ def gradient(f, *varargs, **kwargs):
S0025-5718-1988-0935077-0/S0025-5718-1988-0935077-0.pdf>`_.
"""
f = np.asanyarray(f)
- N = len(f.shape) # number of dimensions
+ N = f.ndim # number of dimensions
axes = kwargs.pop('axis', None)
if axes is None:
@@ -1900,7 +1900,7 @@ def diff(a, n=1, axis=-1):
raise ValueError(
"order must be non-negative but got " + repr(n))
a = asanyarray(a)
- nd = len(a.shape)
+ nd = a.ndim
slice1 = [slice(None)]*nd
slice2 = [slice(None)]*nd
slice1[axis] = slice(1, None)
@@ -2144,7 +2144,7 @@ def unwrap(p, discont=pi, axis=-1):
"""
p = asarray(p)
- nd = len(p.shape)
+ nd = p.ndim
dd = diff(p, axis=axis)
slice1 = [slice(None, None)]*nd # full slices
slice1[axis] = slice(1, None)
@@ -4488,7 +4488,7 @@ def trapz(y, x=None, dx=1.0, axis=-1):
d = d.reshape(shape)
else:
d = diff(x, axis=axis)
- nd = len(y.shape)
+ nd = y.ndim
slice1 = [slice(None)]*nd
slice2 = [slice(None)]*nd
slice1[axis] = slice(1, None)
diff --git a/numpy/lib/npyio.py b/numpy/lib/npyio.py
index c575cc030..0dee6b333 100644
--- a/numpy/lib/npyio.py
+++ b/numpy/lib/npyio.py
@@ -925,7 +925,7 @@ def loadtxt(fname, dtype=float, comments='#', delimiter=None,
flat_dt, flat_packing = flatten_dtype(tp)
types.extend(flat_dt)
# Avoid extra nesting for subarrays
- if len(tp.shape) > 0:
+ if tp.ndim > 0:
packing.extend(flat_packing)
else:
packing.append((len(flat_dt), flat_packing))
diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py
index 281d79ec5..f00d95b6c 100644
--- a/numpy/lib/polynomial.py
+++ b/numpy/lib/polynomial.py
@@ -201,7 +201,7 @@ def roots(p):
"""
# If input is scalar, this makes it an array
p = atleast_1d(p)
- if len(p.shape) != 1:
+ if p.ndim != 1:
raise ValueError("Input must be a rank-1 array.")
# find non-zero array entries
@@ -1051,7 +1051,7 @@ class poly1d(object):
if r:
c_or_r = poly(c_or_r)
c_or_r = atleast_1d(c_or_r)
- if len(c_or_r.shape) > 1:
+ if c_or_r.ndim > 1:
raise ValueError("Polynomial must be 1d only.")
c_or_r = trim_zeros(c_or_r, trim='f')
if len(c_or_r) == 0:
diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py
index 62798286f..8ebcf04b4 100644
--- a/numpy/lib/shape_base.py
+++ b/numpy/lib/shape_base.py
@@ -390,7 +390,7 @@ def dstack(tup):
def _replace_zero_by_x_arrays(sub_arys):
for i in range(len(sub_arys)):
- if len(_nx.shape(sub_arys[i])) == 0:
+ if _nx.ndim(sub_arys[i]) == 0:
sub_arys[i] = _nx.empty(0, dtype=sub_arys[i].dtype)
elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]), 0)):
sub_arys[i] = _nx.empty(0, dtype=sub_arys[i].dtype)
@@ -577,9 +577,9 @@ def hsplit(ary, indices_or_sections):
[[ 6., 7.]]])]
"""
- if len(_nx.shape(ary)) == 0:
+ if _nx.ndim(ary) == 0:
raise ValueError('hsplit only works on arrays of 1 or more dimensions')
- if len(ary.shape) > 1:
+ if ary.ndim > 1:
return split(ary, indices_or_sections, 1)
else:
return split(ary, indices_or_sections, 0)
@@ -631,7 +631,7 @@ def vsplit(ary, indices_or_sections):
[ 6., 7.]]])]
"""
- if len(_nx.shape(ary)) < 2:
+ if _nx.ndim(ary) < 2:
raise ValueError('vsplit only works on arrays of 2 or more dimensions')
return split(ary, indices_or_sections, 0)
@@ -676,7 +676,7 @@ def dsplit(ary, indices_or_sections):
array([], dtype=float64)]
"""
- if len(_nx.shape(ary)) < 3:
+ if _nx.ndim(ary) < 3:
raise ValueError('dsplit only works on arrays of 3 or more dimensions')
return split(ary, indices_or_sections, 2)
diff --git a/numpy/lib/user_array.py b/numpy/lib/user_array.py
index 62398fc3c..f1510a7b1 100644
--- a/numpy/lib/user_array.py
+++ b/numpy/lib/user_array.py
@@ -34,7 +34,7 @@ class container(object):
self.array = array(data, dtype, copy=copy)
def __repr__(self):
- if len(self.shape) > 0:
+ if self.ndim > 0:
return self.__class__.__name__ + repr(self.array)[len("array"):]
else:
return self.__class__.__name__ + "(" + repr(self.array) + ")"
@@ -183,7 +183,7 @@ class container(object):
return self._rc(invert(self.array))
def _scalarfunc(self, func):
- if len(self.shape) == 0:
+ if self.ndim == 0:
return func(self[0])
else:
raise TypeError(