diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-08-18 11:51:25 -0600 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-08-18 11:51:25 -0600 |
commit | fbd6510d58a47ea0d166c48a82793f05425406e4 (patch) | |
tree | 330ce703eb02d20f96099c3fe0fc36ae33d4905b /numpy/lib | |
parent | 8ddb0ce0acafe75d78df528b4d2540dfbf4b364d (diff) | |
download | numpy-fbd6510d58a47ea0d166c48a82793f05425406e4.tar.gz |
STY: Giant comma spacing fixup.
Run the 2to3 ws_comma fixer on *.py files. Some lines are now too long
and will need to be broken at some point. OTOH, some lines were already
too long and need to be broken at some point. Now seems as good a time
as any to do this with open PRs at a minimum.
Diffstat (limited to 'numpy/lib')
31 files changed, 875 insertions, 875 deletions
diff --git a/numpy/lib/__init__.py b/numpy/lib/__init__.py index 64a8550c6..73e4b2306 100644 --- a/numpy/lib/__init__.py +++ b/numpy/lib/__init__.py @@ -24,7 +24,7 @@ from .financial import * from .arrayterator import * from .arraypad import * -__all__ = ['emath','math'] +__all__ = ['emath', 'math'] __all__ += type_check.__all__ __all__ += index_tricks.__all__ __all__ += function_base.__all__ diff --git a/numpy/lib/financial.py b/numpy/lib/financial.py index 8cac117c9..ec642afd3 100644 --- a/numpy/lib/financial.py +++ b/numpy/lib/financial.py @@ -688,7 +688,7 @@ def npv(rate, values): """ values = np.asarray(values) - return (values / (1+rate)**np.arange(0,len(values))).sum(axis=0) + return (values / (1+rate)**np.arange(0, len(values))).sum(axis=0) def mirr(values, finance_rate, reinvest_rate): """ diff --git a/numpy/lib/format.py b/numpy/lib/format.py index fd459e84e..fd5496e96 100644 --- a/numpy/lib/format.py +++ b/numpy/lib/format.py @@ -352,7 +352,7 @@ def read_array_header_1_0(fp): # Sanity-check the values. if (not isinstance(d['shape'], tuple) or - not numpy.all([isinstance(x, (int,long)) for x in d['shape']])): + not numpy.all([isinstance(x, (int, long)) for x in d['shape']])): msg = "shape is not valid: %r" raise ValueError(msg % (d['shape'],)) if not isinstance(d['fortran_order'], bool): @@ -366,7 +366,7 @@ def read_array_header_1_0(fp): return d['shape'], d['fortran_order'], dtype -def write_array(fp, array, version=(1,0)): +def write_array(fp, array, version=(1, 0)): """ Write an array to an NPY file, including a header. @@ -485,7 +485,7 @@ def read_array(fp): def open_memmap(filename, mode='r+', dtype=None, shape=None, - fortran_order=False, version=(1,0)): + fortran_order=False, version=(1, 0)): """ Open a .npy file as a memory-mapped array. diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 4285bf793..91eace2ff 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -351,7 +351,7 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): # Compute the bin number each sample falls into. Ncount = {} for i in arange(D): - Ncount[i] = digitize(sample[:,i], edges[i]) + Ncount[i] = digitize(sample[:, i], edges[i]) # Using digitize, values that fall on an edge are put in the right bin. # For the rightmost bin, we want values equal to the right @@ -362,7 +362,7 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): if not np.isinf(mindiff): decimal = int(-log10(mindiff)) + 6 # Find which points are on the rightmost edge. - on_edge = where(around(sample[:,i], decimal) == around(edges[i][-1], + on_edge = where(around(sample[:, i], decimal) == around(edges[i][-1], decimal))[0] # Shift these points one bin to the left. Ncount[i][on_edge] -= 1 @@ -392,11 +392,11 @@ def histogramdd(sample, bins=10, range=None, normed=False, weights=None): hist = hist.reshape(sort(nbin)) for i in arange(nbin.size): j = ni.argsort()[i] - hist = hist.swapaxes(i,j) - ni[i],ni[j] = ni[j],ni[i] + hist = hist.swapaxes(i, j) + ni[i], ni[j] = ni[j], ni[i] # Remove outliers (indices 0 and -1 for each dimension). - core = D*[slice(1,-1)] + core = D*[slice(1, -1)] hist = hist[core] # Normalize if normed is True @@ -1196,7 +1196,7 @@ def sort_complex(a): array([ 1.+2.j, 2.-1.j, 3.-3.j, 3.-2.j, 3.+5.j]) """ - b = array(a,copy=True) + b = array(a, copy=True) b.sort() if not issubclass(b.dtype.type, _nx.complexfloating): if b.dtype.char in 'bhBH': @@ -1269,7 +1269,7 @@ def unique(x): if tmp.size == 0: return tmp tmp.sort() - idx = concatenate(([True],tmp[1:]!=tmp[:-1])) + idx = concatenate(([True], tmp[1:]!=tmp[:-1])) return tmp[idx] except AttributeError: items = sorted(set(x)) @@ -1736,7 +1736,7 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None): rowvar = 1 if rowvar: axis = 0 - tup = (slice(None),newaxis) + tup = (slice(None), newaxis) else: axis = 1 tup = (newaxis, slice(None)) @@ -1744,7 +1744,7 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None): if y is not None: y = array(y, copy=False, ndmin=2, dtype=float) - X = concatenate((X,y), axis) + X = concatenate((X, y), axis) X -= X.mean(axis=1-axis)[tup] if rowvar: @@ -1820,7 +1820,7 @@ def corrcoef(x, y=None, rowvar=1, bias=0, ddof=None): d = diag(c) except ValueError: # scalar covariance return 1 - return c/sqrt(multiply.outer(d,d)) + return c/sqrt(multiply.outer(d, d)) def blackman(M): """ @@ -1916,7 +1916,7 @@ def blackman(M): return array([]) if M == 1: return ones(1, float) - n = arange(0,M) + n = arange(0, M) return 0.42-0.5*cos(2.0*pi*n/(M-1)) + 0.08*cos(4.0*pi*n/(M-1)) def bartlett(M): @@ -2022,8 +2022,8 @@ def bartlett(M): return array([]) if M == 1: return ones(1, float) - n = arange(0,M) - return where(less_equal(n,(M-1)/2.0),2.0*n/(M-1),2.0-2.0*n/(M-1)) + n = arange(0, M) + return where(less_equal(n, (M-1)/2.0), 2.0*n/(M-1), 2.0-2.0*n/(M-1)) def hanning(M): """ @@ -2120,7 +2120,7 @@ def hanning(M): return array([]) if M == 1: return ones(1, float) - n = arange(0,M) + n = arange(0, M) return 0.5-0.5*cos(2.0*pi*n/(M-1)) def hamming(M): @@ -2216,8 +2216,8 @@ def hamming(M): if M < 1: return array([]) if M == 1: - return ones(1,float) - n = arange(0,M) + return ones(1, float) + n = arange(0, M) return 0.54-0.46*cos(2.0*pi*n/(M-1)) ## Code from cephes for i0 @@ -2285,7 +2285,7 @@ def _chbevl(x, vals): b0 = vals[0] b1 = 0.0 - for i in range(1,len(vals)): + for i in range(1, len(vals)): b2 = b1 b1 = b0 b0 = x*b1 - b2 + vals[i] @@ -2364,7 +2364,7 @@ def i0(x): ## End of cephes code for i0 -def kaiser(M,beta): +def kaiser(M, beta): """ Return the Kaiser window. @@ -2487,7 +2487,7 @@ def kaiser(M,beta): from numpy.dual import i0 if M == 1: return np.array([1.]) - n = arange(0,M) + n = arange(0, M) alpha = (M-1)/2.0 return i0(beta * sqrt(1-((n-alpha)/alpha)**2.0))/i0(float(beta)) @@ -2592,7 +2592,7 @@ def msort(a): ``np.msort(a)`` is equivalent to ``np.sort(a, axis=0)``. """ - b = array(a,subok=True,copy=True) + b = array(a, subok=True, copy=True) b.sort(0) return b @@ -2841,7 +2841,7 @@ def _compute_qth_percentile(sorted, q, axis, out): else: indexer[axis] = slice(i, i+2) j = i + 1 - weights = array([(j - index), (index - i)],float) + weights = array([(j - index), (index - i)], float) wshape = [1]*sorted.ndim wshape[axis] = 2 weights.shape = wshape @@ -2926,8 +2926,8 @@ def trapz(y, x=None, dx=1.0, axis=-1): nd = len(y.shape) slice1 = [slice(None)]*nd slice2 = [slice(None)]*nd - slice1[axis] = slice(1,None) - slice2[axis] = slice(None,-1) + slice1[axis] = slice(1, None) + slice2[axis] = slice(None, -1) try: ret = (d * (y[slice1] +y [slice2]) / 2.0).sum(axis) except ValueError: # Operations didn't work, cast to ndarray @@ -3212,7 +3212,7 @@ def delete(arr, obj, axis=None): if stop == N: pass else: - slobj[axis] = slice(stop-numtodel,None) + slobj[axis] = slice(stop-numtodel, None) slobj2 = [slice(None)]*ndim slobj2[axis] = slice(stop, None) new[slobj] = arr[slobj2] @@ -3253,9 +3253,9 @@ def delete(arr, obj, axis=None): new = empty(newshape, arr.dtype, arr.flags.fnc) slobj[axis] = slice(None, obj) new[slobj] = arr[slobj] - slobj[axis] = slice(obj,None) + slobj[axis] = slice(obj, None) slobj2 = [slice(None)]*ndim - slobj2[axis] = slice(obj+1,None) + slobj2[axis] = slice(obj+1, None) new[slobj] = arr[slobj2] else: if obj.size == 0 and not isinstance(_obj, np.ndarray): diff --git a/numpy/lib/index_tricks.py b/numpy/lib/index_tricks.py index b2ea5e965..570cd0f1d 100644 --- a/numpy/lib/index_tricks.py +++ b/numpy/lib/index_tricks.py @@ -6,8 +6,8 @@ __all__ = ['ravel_multi_index', 'ogrid', 'r_', 'c_', 's_', 'index_exp', 'ix_', - 'ndenumerate','ndindex', - 'fill_diagonal','diag_indices','diag_indices_from'] + 'ndenumerate', 'ndindex', + 'fill_diagonal', 'diag_indices', 'diag_indices_from'] import sys import numpy.core.numeric as _nx @@ -144,7 +144,7 @@ class nd_grid(object): """ def __init__(self, sparse=False): self.sparse = sparse - def __getitem__(self,key): + def __getitem__(self, key): try: size = [] typ = int @@ -180,7 +180,7 @@ class nd_grid(object): if self.sparse: slobj = [_nx.newaxis]*len(size) for k in range(len(size)): - slobj[k] = slice(None,None) + slobj[k] = slice(None, None) nn[k] = nn[k][slobj] slobj[k] = _nx.newaxis return nn @@ -195,12 +195,12 @@ class nd_grid(object): if step != 1: step = (key.stop-start)/float(step-1) stop = key.stop+step - return _nx.arange(0, length,1, float)*step + start + return _nx.arange(0, length, 1, float)*step + start else: return _nx.arange(start, stop, step) - def __getslice__(self,i,j): - return _nx.arange(i,j) + def __getslice__(self, i, j): + return _nx.arange(i, j) def __len__(self): return 0 @@ -237,12 +237,12 @@ class AxisConcatenator(object): self.trans1d = trans1d self.ndmin = ndmin - def __getitem__(self,key): + def __getitem__(self, key): trans1d = self.trans1d ndmin = self.ndmin if isinstance(key, str): frame = sys._getframe().f_back - mymat = matrix.bmat(key,frame.f_globals,frame.f_locals) + mymat = matrix.bmat(key, frame.f_globals, frame.f_locals) return mymat if not isinstance(key, tuple): key = (key,) @@ -265,10 +265,10 @@ class AxisConcatenator(object): else: newobj = _nx.arange(start, stop, step) if ndmin > 1: - newobj = array(newobj,copy=False,ndmin=ndmin) + newobj = array(newobj, copy=False, ndmin=ndmin) if trans1d != -1: - newobj = newobj.swapaxes(-1,trans1d) - elif isinstance(key[k],str): + newobj = newobj.swapaxes(-1, trans1d) + elif isinstance(key[k], str): if k != 0: raise ValueError("special directives must be the " "first entry.") @@ -293,7 +293,7 @@ class AxisConcatenator(object): except (ValueError, TypeError): raise ValueError("unknown special directive") elif type(key[k]) in ScalarType: - newobj = array(key[k],ndmin=ndmin) + newobj = array(key[k], ndmin=ndmin) scalars.append(k) scalar = True scalartypes.append(newobj.dtype) @@ -323,11 +323,11 @@ class AxisConcatenator(object): for k in scalars: objs[k] = objs[k].astype(final_dtype) - res = _nx.concatenate(tuple(objs),axis=self.axis) + res = _nx.concatenate(tuple(objs), axis=self.axis) return self._retval(res) - def __getslice__(self,i,j): - res = _nx.arange(i,j) + def __getslice__(self, i, j): + res = _nx.arange(i, j) return self._retval(res) def __len__(self): diff --git a/numpy/lib/info.py b/numpy/lib/info.py index 94eeae503..3fbbab769 100644 --- a/numpy/lib/info.py +++ b/numpy/lib/info.py @@ -147,5 +147,5 @@ setdiff1d Set difference of 1D arrays with unique elements. """ from __future__ import division, absolute_import, print_function -depends = ['core','testing'] +depends = ['core', 'testing'] global_symbols = ['*'] diff --git a/numpy/lib/polynomial.py b/numpy/lib/polynomial.py index 5402adc6d..48a012c9c 100644 --- a/numpy/lib/polynomial.py +++ b/numpy/lib/polynomial.py @@ -141,7 +141,7 @@ def poly(seq_of_zeros): roots = NX.asarray(seq_of_zeros, complex) pos_roots = sort_complex(NX.compress(roots.imag > 0, roots)) neg_roots = NX.conjugate(sort_complex( - NX.compress(roots.imag < 0,roots))) + NX.compress(roots.imag < 0, roots))) if (len(pos_roots) == len(neg_roots) and NX.alltrue(neg_roots == pos_roots)): a = a.real.copy() @@ -223,7 +223,7 @@ def roots(p): if N > 1: # build companion matrix and find its eigenvalues (the roots) A = diag(NX.ones((N-2,), p.dtype), -1) - A[0, :] = -p[1:] / p[0] + A[0,:] = -p[1:] / p[0] roots = eigvals(A) else: roots = NX.array([]) @@ -589,7 +589,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False): if full : return c, resids, rank, s, rcond elif cov : - Vbase = inv(dot(lhs.T,lhs)) + Vbase = inv(dot(lhs.T, lhs)) Vbase /= NX.outer(scale, scale) # Some literature ignores the extra -2.0 factor in the denominator, but # it is included here because the covariance of Multivariate Student-T @@ -599,7 +599,7 @@ def polyfit(x, y, deg, rcond=None, full=False, w=None, cov=False): if y.ndim == 1: return c, Vbase * fac else: - return c, Vbase[:,:,NX.newaxis] * fac + return c, Vbase[:,:, NX.newaxis] * fac else : return c @@ -828,7 +828,7 @@ def polymul(a1, a2): """ truepoly = (isinstance(a1, poly1d) or isinstance(a2, poly1d)) - a1,a2 = poly1d(a1),poly1d(a2) + a1, a2 = poly1d(a1), poly1d(a2) val = NX.convolve(a1, a2) if truepoly: val = poly1d(val) @@ -1200,7 +1200,7 @@ class poly1d(object): def __getattr__(self, key): if key in ['r', 'roots']: return roots(self.coeffs) - elif key in ['c','coef','coefficients']: + elif key in ['c', 'coef', 'coefficients']: return self.coeffs elif key in ['o']: return self.order @@ -1261,4 +1261,4 @@ class poly1d(object): # Stuff to do on module import -warnings.simplefilter('always',RankWarning) +warnings.simplefilter('always', RankWarning) diff --git a/numpy/lib/recfunctions.py b/numpy/lib/recfunctions.py index 827e60d70..ae4ee56c6 100644 --- a/numpy/lib/recfunctions.py +++ b/numpy/lib/recfunctions.py @@ -900,7 +900,7 @@ def join_by(key, r1, r2, jointype='inner', r1postfix='1', r2postfix='2', (r1names, r2names) = (r1.dtype.names, r2.dtype.names) # Check the names for collision - if (set.intersection(set(r1names),set(r2names)).difference(key) and + if (set.intersection(set(r1names), set(r2names)).difference(key) and not (r1postfix or r2postfix)): msg = "r1 and r2 contain common names, r1postfix and r2postfix " msg += "can't be empty" diff --git a/numpy/lib/scimath.py b/numpy/lib/scimath.py index 2aa08d0ea..3da86d9c8 100644 --- a/numpy/lib/scimath.py +++ b/numpy/lib/scimath.py @@ -17,7 +17,7 @@ correctly handled. See their respective docstrings for specific examples. """ from __future__ import division, absolute_import, print_function -__all__ = ['sqrt', 'log', 'log2', 'logn','log10', 'power', 'arccos', +__all__ = ['sqrt', 'log', 'log2', 'logn', 'log10', 'power', 'arccos', 'arcsin', 'arctanh'] import numpy.core.numeric as nx @@ -84,7 +84,7 @@ def _tocomplex(arr): array([ 1.+0.j, 2.+0.j, 3.+0.j], dtype=complex64) """ if issubclass(arr.dtype.type, (nt.single, nt.byte, nt.short, nt.ubyte, - nt.ushort,nt.csingle)): + nt.ushort, nt.csingle)): return arr.astype(nt.csingle) else: return arr.astype(nt.cdouble) diff --git a/numpy/lib/setup.py b/numpy/lib/setup.py index edc653f9f..153af314c 100644 --- a/numpy/lib/setup.py +++ b/numpy/lib/setup.py @@ -5,13 +5,13 @@ from os.path import join def configuration(parent_package='',top_path=None): from numpy.distutils.misc_util import Configuration - config = Configuration('lib',parent_package,top_path) + config = Configuration('lib', parent_package, top_path) - config.add_include_dirs(join('..','core','include')) + config.add_include_dirs(join('..', 'core', 'include')) config.add_extension('_compiled_base', - sources=[join('src','_compiled_base.c')] + sources=[join('src', '_compiled_base.c')] ) config.add_data_dir('benchmarks') diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index c63f8140d..1363a3213 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -1,7 +1,7 @@ from __future__ import division, absolute_import, print_function -__all__ = ['column_stack','row_stack', 'dstack','array_split','split','hsplit', - 'vsplit','dsplit','apply_over_axes','expand_dims', +__all__ = ['column_stack', 'row_stack', 'dstack', 'array_split', 'split', 'hsplit', + 'vsplit', 'dsplit', 'apply_over_axes', 'expand_dims', 'apply_along_axis', 'kron', 'tile', 'get_array_wrap'] import numpy.core.numeric as _nx @@ -68,18 +68,18 @@ def apply_along_axis(func1d,axis,arr,*args): axis += nd if (axis >= nd): raise ValueError("axis must be less than arr.ndim; axis=%d, rank=%d." - % (axis,nd)) + % (axis, nd)) ind = [0]*(nd-1) - i = zeros(nd,'O') + i = zeros(nd, 'O') indlist = list(range(nd)) indlist.remove(axis) - i[axis] = slice(None,None) + i[axis] = slice(None, None) outshape = asarray(arr.shape).take(indlist) i.put(indlist, ind) res = func1d(arr[tuple(i.tolist())],*args) # if res is a number, then we have a smaller output array if isscalar(res): - outarr = zeros(outshape,asarray(res).dtype) + outarr = zeros(outshape, asarray(res).dtype) outarr[tuple(ind)] = res Ntot = product(outshape) k = 1 @@ -91,7 +91,7 @@ def apply_along_axis(func1d,axis,arr,*args): ind[n-1] += 1 ind[n] = 0 n -= 1 - i.put(indlist,ind) + i.put(indlist, ind) res = func1d(arr[tuple(i.tolist())],*args) outarr[tuple(ind)] = res k += 1 @@ -101,7 +101,7 @@ def apply_along_axis(func1d,axis,arr,*args): holdshape = outshape outshape = list(arr.shape) outshape[axis] = len(res) - outarr = zeros(outshape,asarray(res).dtype) + outarr = zeros(outshape, asarray(res).dtype) outarr[tuple(i.tolist())] = res k = 1 while k < Ntot: @@ -182,7 +182,7 @@ def apply_over_axes(func, a, axes): if res.ndim == val.ndim: val = res else: - res = expand_dims(res,axis) + res = expand_dims(res, axis) if res.ndim == val.ndim: val = res else: @@ -288,11 +288,11 @@ def column_stack(tup): """ arrays = [] for v in tup: - arr = array(v,copy=False,subok=True) + arr = array(v, copy=False, subok=True) if arr.ndim < 2: - arr = array(arr,copy=False,subok=True,ndmin=2).T + arr = array(arr, copy=False, subok=True, ndmin=2).T arrays.append(arr) - return _nx.concatenate(arrays,1) + return _nx.concatenate(arrays, 1) def dstack(tup): """ @@ -348,7 +348,7 @@ def _replace_zero_by_x_arrays(sub_arys): for i in range(len(sub_arys)): if len(_nx.shape(sub_arys[i])) == 0: sub_arys[i] = _nx.array([]) - elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]),0)): + elif _nx.sometrue(_nx.equal(_nx.shape(sub_arys[i]), 0)): sub_arys[i] = _nx.array([]) return sub_arys @@ -383,17 +383,17 @@ def array_split(ary,indices_or_sections,axis = 0): Nsections = int(indices_or_sections) if Nsections <= 0: raise ValueError('number sections must be larger than 0.') - Neach_section,extras = divmod(Ntotal,Nsections) + Neach_section, extras = divmod(Ntotal, Nsections) section_sizes = [0] + \ extras * [Neach_section+1] + \ (Nsections-extras) * [Neach_section] div_points = _nx.array(section_sizes).cumsum() sub_arys = [] - sary = _nx.swapaxes(ary,axis,0) + sary = _nx.swapaxes(ary, axis, 0) for i in range(Nsections): st = div_points[i]; end = div_points[i+1] - sub_arys.append(_nx.swapaxes(sary[st:end],axis,0)) + sub_arys.append(_nx.swapaxes(sary[st:end], axis, 0)) # there is a weird issue with array slicing that allows # 0x10 arrays and other such things. The following kludge is needed @@ -474,10 +474,10 @@ def split(ary,indices_or_sections,axis=0): N = ary.shape[axis] if N % sections: raise ValueError('array split does not result in an equal division') - res = array_split(ary,indices_or_sections,axis) + res = array_split(ary, indices_or_sections, axis) return res -def hsplit(ary,indices_or_sections): +def hsplit(ary, indices_or_sections): """ Split an array into multiple sub-arrays horizontally (column-wise). @@ -535,11 +535,11 @@ def hsplit(ary,indices_or_sections): if len(_nx.shape(ary)) == 0: raise ValueError('hsplit only works on arrays of 1 or more dimensions') if len(ary.shape) > 1: - return split(ary,indices_or_sections,1) + return split(ary, indices_or_sections, 1) else: - return split(ary,indices_or_sections,0) + return split(ary, indices_or_sections, 0) -def vsplit(ary,indices_or_sections): +def vsplit(ary, indices_or_sections): """ Split an array into multiple sub-arrays vertically (row-wise). @@ -588,9 +588,9 @@ def vsplit(ary,indices_or_sections): """ if len(_nx.shape(ary)) < 2: raise ValueError('vsplit only works on arrays of 2 or more dimensions') - return split(ary,indices_or_sections,0) + return split(ary, indices_or_sections, 0) -def dsplit(ary,indices_or_sections): +def dsplit(ary, indices_or_sections): """ Split array into multiple sub-arrays along the 3rd axis (depth). @@ -633,7 +633,7 @@ def dsplit(ary,indices_or_sections): """ if len(_nx.shape(ary)) < 3: raise ValueError('vsplit only works on arrays of 3 or more dimensions') - return split(ary,indices_or_sections,2) + return split(ary, indices_or_sections, 2) def get_array_prepare(*args): """Find the wrapper for the array with the highest priority. @@ -659,7 +659,7 @@ def get_array_wrap(*args): return wrappers[-1][-1] return None -def kron(a,b): +def kron(a, b): """ Kronecker product of two arrays. @@ -728,10 +728,10 @@ def kron(a,b): """ b = asanyarray(b) - a = array(a,copy=False,subok=True,ndmin=b.ndim) + a = array(a, copy=False, subok=True, ndmin=b.ndim) ndb, nda = b.ndim, a.ndim if (nda == 0 or ndb == 0): - return _nx.multiply(a,b) + return _nx.multiply(a, b) as_ = a.shape bs = b.shape if not a.flags.contiguous: @@ -745,7 +745,7 @@ def kron(a,b): else: bs = (1,)*(nda-ndb) + bs nd = nda - result = outer(a,b).reshape(as_+bs) + result = outer(a, b).reshape(as_+bs) axis = nd-1 for _ in range(nd): result = concatenate(result, axis=axis) @@ -819,14 +819,14 @@ def tile(A, reps): except TypeError: tup = (reps,) d = len(tup) - c = _nx.array(A,copy=False,subok=True,ndmin=d) + c = _nx.array(A, copy=False, subok=True, ndmin=d) shape = list(c.shape) - n = max(c.size,1) + n = max(c.size, 1) if (d < c.ndim): tup = (1,)*(c.ndim-d) + tup for i, nrep in enumerate(tup): if nrep!=1: - c = c.reshape(-1,n).repeat(nrep,0) + c = c.reshape(-1, n).repeat(nrep, 0) dim_in = shape[i] dim_out = dim_in*nrep shape[i] = dim_out diff --git a/numpy/lib/stride_tricks.py b/numpy/lib/stride_tricks.py index 7b6b06fdc..d092f92a8 100644 --- a/numpy/lib/stride_tricks.py +++ b/numpy/lib/stride_tricks.py @@ -115,6 +115,6 @@ def broadcast_arrays(*args): common_shape.append(1) # Construct the new arrays. - broadcasted = [as_strided(x, shape=sh, strides=st) for (x,sh,st) in + broadcasted = [as_strided(x, shape=sh, strides=st) for (x, sh, st) in zip(args, shapes, strides)] return broadcasted diff --git a/numpy/lib/tests/test_arraysetops.py b/numpy/lib/tests/test_arraysetops.py index 4ba6529e4..7e8a7a6f3 100644 --- a/numpy/lib/tests/test_arraysetops.py +++ b/numpy/lib/tests/test_arraysetops.py @@ -61,8 +61,8 @@ class TestSetOps(TestCase): # test for structured arrays dt = [('', 'i'), ('', 'i')] - aa = np.array(list(zip(a,a)), dt) - bb = np.array(list(zip(b,b)), dt) + aa = np.array(list(zip(a, a)), dt) + bb = np.array(list(zip(b, b)), dt) check_all(aa, bb, i1, i2, dt) @@ -83,7 +83,7 @@ class TestSetOps(TestCase): c = intersect1d( a, b ) assert_array_equal( c, ed ) - assert_array_equal([], intersect1d([],[])) + assert_array_equal([], intersect1d([], [])) def test_setxor1d( self ): a = np.array( [5, 7, 1, 2] ) @@ -107,19 +107,19 @@ class TestSetOps(TestCase): c = setxor1d( a, b ) assert_array_equal( c, ec ) - assert_array_equal([], setxor1d([],[])) + assert_array_equal([], setxor1d([], [])) def test_ediff1d(self): zero_elem = np.array([]) one_elem = np.array([1]) - two_elem = np.array([1,2]) + two_elem = np.array([1, 2]) - assert_array_equal([],ediff1d(zero_elem)) - assert_array_equal([0],ediff1d(zero_elem,to_begin=0)) - assert_array_equal([0],ediff1d(zero_elem,to_end=0)) - assert_array_equal([-1,0],ediff1d(zero_elem,to_begin=-1,to_end=0)) - assert_array_equal([],ediff1d(one_elem)) - assert_array_equal([1],ediff1d(two_elem)) + assert_array_equal([], ediff1d(zero_elem)) + assert_array_equal([0], ediff1d(zero_elem, to_begin=0)) + assert_array_equal([0], ediff1d(zero_elem, to_end=0)) + assert_array_equal([-1, 0], ediff1d(zero_elem, to_begin=-1, to_end=0)) + assert_array_equal([], ediff1d(one_elem)) + assert_array_equal([1], ediff1d(two_elem)) def test_in1d(self): # we use two different sizes for the b array here to test the @@ -182,8 +182,8 @@ class TestSetOps(TestCase): assert_array_equal(in1d([], []), []) def test_in1d_char_array( self ): - a = np.array(['a', 'b', 'c','d','e','c','e','b']) - b = np.array(['a','c']) + a = np.array(['a', 'b', 'c', 'd', 'e', 'c', 'e', 'b']) + b = np.array(['a', 'c']) ec = np.array([True, False, True, False, False, True, False, False]) c = in1d(a, b) @@ -202,9 +202,9 @@ class TestSetOps(TestCase): def test_in1d_ravel(self): # Test that in1d ravels its input arrays. This is not documented # behavior however. The test is to ensure consistentency. - a = np.arange(6).reshape(2,3) - b = np.arange(3,9).reshape(3,2) - long_b = np.arange(3, 63).reshape(30,2) + a = np.arange(6).reshape(2, 3) + b = np.arange(3, 9).reshape(3, 2) + long_b = np.arange(3, 63).reshape(30, 2) ec = np.array([False, False, False, True, True, True]) assert_array_equal(in1d(a, b, assume_unique=True), ec) @@ -220,7 +220,7 @@ class TestSetOps(TestCase): c = union1d( a, b ) assert_array_equal( c, ec ) - assert_array_equal([], union1d([],[])) + assert_array_equal([], union1d([], [])) def test_setdiff1d( self ): a = np.array( [6, 5, 4, 7, 1, 2, 7, 4] ) @@ -236,12 +236,12 @@ class TestSetOps(TestCase): c = setdiff1d( a, b ) assert_array_equal( c, ec ) - assert_array_equal([], setdiff1d([],[])) + assert_array_equal([], setdiff1d([], [])) def test_setdiff1d_char_array(self): - a = np.array(['a','b','c']) - b = np.array(['a','b','s']) - assert_array_equal(setdiff1d(a,b),np.array(['c'])) + a = np.array(['a', 'b', 'c']) + b = np.array(['a', 'b', 's']) + assert_array_equal(setdiff1d(a, b), np.array(['c'])) def test_manyways( self ): a = np.array( [5, 7, 1, 2, 8] ) diff --git a/numpy/lib/tests/test_financial.py b/numpy/lib/tests/test_financial.py index 1a276a429..1894da8cb 100644 --- a/numpy/lib/tests/test_financial.py +++ b/numpy/lib/tests/test_financial.py @@ -5,7 +5,7 @@ import numpy as np class TestFinancial(TestCase): def test_rate(self): - assert_almost_equal(np.rate(10,0,-3500,10000), + assert_almost_equal(np.rate(10, 0, -3500, 10000), 0.1107, 4) def test_irr(self): @@ -14,127 +14,127 @@ class TestFinancial(TestCase): 0.0524, 2) def test_pv(self): - assert_almost_equal(np.pv(0.07,20,12000,0), + assert_almost_equal(np.pv(0.07, 20, 12000, 0), -127128.17, 2) def test_fv(self): - assert_almost_equal(np.fv(0.075, 20, -2000,0,0), + assert_almost_equal(np.fv(0.075, 20, -2000, 0, 0), 86609.36, 2) def test_pmt(self): - assert_almost_equal(np.pmt(0.08/12,5*12,15000), + assert_almost_equal(np.pmt(0.08/12, 5*12, 15000), -304.146, 3) def test_ppmt(self): - np.round(np.ppmt(0.1/12,1,60,55000),2) == 710.25 + np.round(np.ppmt(0.1/12, 1, 60, 55000), 2) == 710.25 def test_ipmt(self): - np.round(np.ipmt(0.1/12,1,24,2000),2) == 16.67 + np.round(np.ipmt(0.1/12, 1, 24, 2000), 2) == 16.67 def test_nper(self): - assert_almost_equal(np.nper(0.075,-2000,0,100000.), + assert_almost_equal(np.nper(0.075, -2000, 0, 100000.), 21.54, 2) def test_nper2(self): - assert_almost_equal(np.nper(0.0,-2000,0,100000.), + assert_almost_equal(np.nper(0.0, -2000, 0, 100000.), 50.0, 1) def test_npv(self): - assert_almost_equal(np.npv(0.05,[-15000,1500,2500,3500,4500,6000]), + assert_almost_equal(np.npv(0.05, [-15000, 1500, 2500, 3500, 4500, 6000]), 122.89, 2) def test_mirr(self): - val = [-4500,-800,800,800,600,600,800,800,700,3000] + val = [-4500, -800, 800, 800, 600, 600, 800, 800, 700, 3000] assert_almost_equal(np.mirr(val, 0.08, 0.055), 0.0666, 4) - val = [-120000,39000,30000,21000,37000,46000] + val = [-120000, 39000, 30000, 21000, 37000, 46000] assert_almost_equal(np.mirr(val, 0.10, 0.12), 0.126094, 6) - val = [100,200,-50,300,-200] + val = [100, 200, -50, 300, -200] assert_almost_equal(np.mirr(val, 0.05, 0.06), 0.3428, 4) - val = [39000,30000,21000,37000,46000] + val = [39000, 30000, 21000, 37000, 46000] assert_(np.isnan(np.mirr(val, 0.10, 0.12))) def test_when(self): #begin - assert_almost_equal(np.rate(10,20,-3500,10000,1), - np.rate(10,20,-3500,10000,'begin'), 4) + assert_almost_equal(np.rate(10, 20, -3500, 10000, 1), + np.rate(10, 20, -3500, 10000, 'begin'), 4) #end - assert_almost_equal(np.rate(10,20,-3500,10000), - np.rate(10,20,-3500,10000,'end'), 4) - assert_almost_equal(np.rate(10,20,-3500,10000,0), - np.rate(10,20,-3500,10000,'end'), 4) + assert_almost_equal(np.rate(10, 20, -3500, 10000), + np.rate(10, 20, -3500, 10000, 'end'), 4) + assert_almost_equal(np.rate(10, 20, -3500, 10000, 0), + np.rate(10, 20, -3500, 10000, 'end'), 4) # begin - assert_almost_equal(np.pv(0.07,20,12000,0,1), - np.pv(0.07,20,12000,0,'begin'), 2) + assert_almost_equal(np.pv(0.07, 20, 12000, 0, 1), + np.pv(0.07, 20, 12000, 0, 'begin'), 2) # end - assert_almost_equal(np.pv(0.07,20,12000,0), - np.pv(0.07,20,12000,0,'end'), 2) - assert_almost_equal(np.pv(0.07,20,12000,0,0), - np.pv(0.07,20,12000,0,'end'), 2) + assert_almost_equal(np.pv(0.07, 20, 12000, 0), + np.pv(0.07, 20, 12000, 0, 'end'), 2) + assert_almost_equal(np.pv(0.07, 20, 12000, 0, 0), + np.pv(0.07, 20, 12000, 0, 'end'), 2) # begin - assert_almost_equal(np.fv(0.075, 20, -2000,0,1), - np.fv(0.075, 20, -2000,0,'begin'), 4) + assert_almost_equal(np.fv(0.075, 20, -2000, 0, 1), + np.fv(0.075, 20, -2000, 0, 'begin'), 4) # end - assert_almost_equal(np.fv(0.075, 20, -2000,0), - np.fv(0.075, 20, -2000,0,'end'), 4) - assert_almost_equal(np.fv(0.075, 20, -2000,0,0), - np.fv(0.075, 20, -2000,0,'end'), 4) + assert_almost_equal(np.fv(0.075, 20, -2000, 0), + np.fv(0.075, 20, -2000, 0, 'end'), 4) + assert_almost_equal(np.fv(0.075, 20, -2000, 0, 0), + np.fv(0.075, 20, -2000, 0, 'end'), 4) # begin - assert_almost_equal(np.pmt(0.08/12,5*12,15000.,0,1), - np.pmt(0.08/12,5*12,15000.,0,'begin'), 4) + assert_almost_equal(np.pmt(0.08/12, 5*12, 15000., 0, 1), + np.pmt(0.08/12, 5*12, 15000., 0, 'begin'), 4) # end - assert_almost_equal(np.pmt(0.08/12,5*12,15000.,0), - np.pmt(0.08/12,5*12,15000.,0,'end'), 4) - assert_almost_equal(np.pmt(0.08/12,5*12,15000.,0,0), - np.pmt(0.08/12,5*12,15000.,0,'end'), 4) + assert_almost_equal(np.pmt(0.08/12, 5*12, 15000., 0), + np.pmt(0.08/12, 5*12, 15000., 0, 'end'), 4) + assert_almost_equal(np.pmt(0.08/12, 5*12, 15000., 0, 0), + np.pmt(0.08/12, 5*12, 15000., 0, 'end'), 4) # begin - assert_almost_equal(np.ppmt(0.1/12,1,60,55000,0,1), - np.ppmt(0.1/12,1,60,55000,0,'begin'), 4) + assert_almost_equal(np.ppmt(0.1/12, 1, 60, 55000, 0, 1), + np.ppmt(0.1/12, 1, 60, 55000, 0, 'begin'), 4) # end - assert_almost_equal(np.ppmt(0.1/12,1,60,55000,0), - np.ppmt(0.1/12,1,60,55000,0,'end'), 4) - assert_almost_equal(np.ppmt(0.1/12,1,60,55000,0,0), - np.ppmt(0.1/12,1,60,55000,0,'end'), 4) + assert_almost_equal(np.ppmt(0.1/12, 1, 60, 55000, 0), + np.ppmt(0.1/12, 1, 60, 55000, 0, 'end'), 4) + assert_almost_equal(np.ppmt(0.1/12, 1, 60, 55000, 0, 0), + np.ppmt(0.1/12, 1, 60, 55000, 0, 'end'), 4) # begin - assert_almost_equal(np.ipmt(0.1/12,1,24,2000,0,1), - np.ipmt(0.1/12,1,24,2000,0,'begin'), 4) + assert_almost_equal(np.ipmt(0.1/12, 1, 24, 2000, 0, 1), + np.ipmt(0.1/12, 1, 24, 2000, 0, 'begin'), 4) # end - assert_almost_equal(np.ipmt(0.1/12,1,24,2000,0), - np.ipmt(0.1/12,1,24,2000,0,'end'), 4) - assert_almost_equal(np.ipmt(0.1/12,1,24,2000,0,0), - np.ipmt(0.1/12,1,24,2000,0,'end'), 4) + assert_almost_equal(np.ipmt(0.1/12, 1, 24, 2000, 0), + np.ipmt(0.1/12, 1, 24, 2000, 0, 'end'), 4) + assert_almost_equal(np.ipmt(0.1/12, 1, 24, 2000, 0, 0), + np.ipmt(0.1/12, 1, 24, 2000, 0, 'end'), 4) # begin - assert_almost_equal(np.nper(0.075,-2000,0,100000.,1), - np.nper(0.075,-2000,0,100000.,'begin'), 4) + assert_almost_equal(np.nper(0.075, -2000, 0, 100000., 1), + np.nper(0.075, -2000, 0, 100000., 'begin'), 4) # end - assert_almost_equal(np.nper(0.075,-2000,0,100000.), - np.nper(0.075,-2000,0,100000.,'end'), 4) - assert_almost_equal(np.nper(0.075,-2000,0,100000.,0), - np.nper(0.075,-2000,0,100000.,'end'), 4) + assert_almost_equal(np.nper(0.075, -2000, 0, 100000.), + np.nper(0.075, -2000, 0, 100000., 'end'), 4) + assert_almost_equal(np.nper(0.075, -2000, 0, 100000., 0), + np.nper(0.075, -2000, 0, 100000., 'end'), 4) def test_broadcast(self): - assert_almost_equal(np.nper(0.075,-2000,0,100000.,[0,1]), - [ 21.5449442 , 20.76156441], 4) + assert_almost_equal(np.nper(0.075, -2000, 0, 100000., [0, 1]), + [ 21.5449442, 20.76156441], 4) - assert_almost_equal(np.ipmt(0.1/12,list(range(5)), 24, 2000), + assert_almost_equal(np.ipmt(0.1/12, list(range(5)), 24, 2000), [-17.29165168, -16.66666667, -16.03647345, -15.40102862, -14.76028842], 4) - assert_almost_equal(np.ppmt(0.1/12,list(range(5)), 24, 2000), - [-74.998201 , -75.62318601, -76.25337923, + assert_almost_equal(np.ppmt(0.1/12, list(range(5)), 24, 2000), + [-74.998201, -75.62318601, -76.25337923, -76.88882405, -77.52956425], 4) - assert_almost_equal(np.ppmt(0.1/12,list(range(5)), 24, 2000, 0, - [0,0,1,'end','begin']), - [-74.998201 , -75.62318601, -75.62318601, + assert_almost_equal(np.ppmt(0.1/12, list(range(5)), 24, 2000, 0, + [0, 0, 1, 'end', 'begin']), + [-74.998201, -75.62318601, -75.62318601, -76.88882405, -76.88882405], 4) if __name__ == "__main__": diff --git a/numpy/lib/tests/test_format.py b/numpy/lib/tests/test_format.py index 8b809891f..694dc4591 100644 --- a/numpy/lib/tests/test_format.py +++ b/numpy/lib/tests/test_format.py @@ -331,11 +331,11 @@ for scalar in scalars: # 1-D basic, # 2-D C-contiguous - basic.reshape((3,5)), + basic.reshape((3, 5)), # 2-D F-contiguous - basic.reshape((3,5)).T, + basic.reshape((3, 5)).T, # 2-D non-contiguous - basic.reshape((3,5))[::-1,::2], + basic.reshape((3, 5))[::-1, ::2], ]) # More complicated record arrays. @@ -354,8 +354,8 @@ Pdescr = [ # A plain list of tuples with values for testing: PbufferT = [ # x y z - ([3,2], [[6.,4.],[6.,4.]], 8), - ([4,3], [[7.,5.],[7.,5.]], 9), + ([3, 2], [[6., 4.], [6., 4.]], 8), + ([4, 3], [[7., 5.], [7., 5.]], 9), ] @@ -394,8 +394,8 @@ NbufferT = [ # x Info color info y z # value y2 Info2 name z2 Name Value # name value y3 z3 - ([3,2], (6j, 6., ('nn', [6j,4j], [6.,4.], [1,2]), 'NN', True), 'cc', ('NN', 6j), [[6.,4.],[6.,4.]], 8), - ([4,3], (7j, 7., ('oo', [7j,5j], [7.,5.], [2,1]), 'OO', False), 'dd', ('OO', 7j), [[7.,5.],[7.,5.]], 9), + ([3, 2], (6j, 6., ('nn', [6j, 4j], [6., 4.], [1, 2]), 'NN', True), 'cc', ('NN', 6j), [[6., 4.], [6., 4.]], 8), + ([4, 3], (7j, 7., ('oo', [7j, 5j], [7., 5.], [2, 1]), 'OO', False), 'dd', ('OO', 7j), [[7., 5.], [7., 5.]], 9), ] record_arrays = [ @@ -520,7 +520,7 @@ def test_bad_magic_args(): def test_large_header(): s = BytesIO() d = {'a':1,'b':2} - format.write_array_header_1_0(s,d) + format.write_array_header_1_0(s, d) s = BytesIO() d = {'a':1,'b':2,'c':'x'*256*256} @@ -538,18 +538,18 @@ def test_bad_header(): assert_raises(ValueError, format.read_array_header_1_0, s) # headers without the exact keys required should fail - d = {"shape":(1,2), + d = {"shape":(1, 2), "descr":"x"} s = BytesIO() - format.write_array_header_1_0(s,d) + format.write_array_header_1_0(s, d) assert_raises(ValueError, format.read_array_header_1_0, s) - d = {"shape":(1,2), + d = {"shape":(1, 2), "fortran_order":False, "descr":"x", "extrakey":-1} s = BytesIO() - format.write_array_header_1_0(s,d) + format.write_array_header_1_0(s, d) assert_raises(ValueError, format.read_array_header_1_0, s) if __name__ == "__main__": diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index 65519d0bc..28f094653 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -174,10 +174,10 @@ class TestInsert(TestCase): assert_equal(insert(a, 0, 1), [1, 1, 2, 3]) assert_equal(insert(a, 3, 1), [1, 2, 3, 1]) assert_equal(insert(a, [1, 1, 1], [1, 2, 3]), [1, 1, 2, 3, 2, 3]) - assert_equal(insert(a, 1,[1,2,3]), [1, 1, 2, 3, 2, 3]) - assert_equal(insert(a,[1,-1,3],9),[1,9,2,9,3,9]) - assert_equal(insert(a,slice(-1,None,-1), 9),[9,1,9,2,9,3]) - assert_equal(insert(a,[-1,1,3], [7,8,9]),[1,8,2,7,3,9]) + assert_equal(insert(a, 1, [1, 2, 3]), [1, 1, 2, 3, 2, 3]) + assert_equal(insert(a, [1, -1, 3], 9), [1, 9, 2, 9, 3, 9]) + assert_equal(insert(a, slice(-1, None, -1), 9), [9, 1, 9, 2, 9, 3]) + assert_equal(insert(a, [-1, 1, 3], [7, 8, 9]), [1, 8, 2, 7, 3, 9]) b = np.array([0, 1], dtype=np.float64) assert_equal(insert(b, 0, b[0]), [0., 0., 1.]) assert_equal(insert(b, [], []), b) @@ -185,42 +185,42 @@ class TestInsert(TestCase): #assert_equal(insert(a, np.array([True]*4), 9), [9,1,9,2,9,3,9]) with warnings.catch_warnings(record=True) as w: warnings.filterwarnings('always', '', FutureWarning) - assert_equal(insert(a, np.array([True]*4), 9), [1,9,9,9,9,2,3]) + assert_equal(insert(a, np.array([True]*4), 9), [1, 9, 9, 9, 9, 2, 3]) assert_(w[0].category is FutureWarning) def test_multidim(self): a = [[1, 1, 1]] r = [[2, 2, 2], [1, 1, 1]] - assert_equal(insert(a, 0, [1]), [1,1,1,1]) + assert_equal(insert(a, 0, [1]), [1, 1, 1, 1]) assert_equal(insert(a, 0, [2, 2, 2], axis=0), r) assert_equal(insert(a, 0, 2, axis=0), r) assert_equal(insert(a, 2, 2, axis=1), [[1, 1, 2, 1]]) a = np.array([[1, 1], [2, 2], [3, 3]]) - b = np.arange(1,4).repeat(3).reshape(3,3) - c = np.concatenate((a[:,0:1], np.arange(1,4).repeat(3).reshape(3,3).T, - a[:,1:2]), axis=1) - assert_equal(insert(a, [1], [[1],[2],[3]], axis=1), b) + b = np.arange(1, 4).repeat(3).reshape(3, 3) + c = np.concatenate((a[:, 0:1], np.arange(1, 4).repeat(3).reshape(3, 3).T, + a[:, 1:2]), axis=1) + assert_equal(insert(a, [1], [[1], [2], [3]], axis=1), b) assert_equal(insert(a, [1], [1, 2, 3], axis=1), c) # scalars behave differently, in this case exactly opposite: assert_equal(insert(a, 1, [1, 2, 3], axis=1), b) - assert_equal(insert(a, 1, [[1],[2],[3]], axis=1), c) + assert_equal(insert(a, 1, [[1], [2], [3]], axis=1), c) - a = np.arange(4).reshape(2,2) - assert_equal(insert(a[:,:1], 1, a[:,1], axis=1), a) + a = np.arange(4).reshape(2, 2) + assert_equal(insert(a[:, :1], 1, a[:, 1], axis=1), a) assert_equal(insert(a[:1,:], 1, a[1,:], axis=0), a) # negative axis value - a = np.arange(24).reshape((2,3,4)) - assert_equal(insert(a, 1, a[:,:,3], axis=-1), - insert(a, 1, a[:,:,3], axis=2)) - assert_equal(insert(a, 1, a[:,2,:], axis=-2), - insert(a, 1, a[:,2,:], axis=1)) + a = np.arange(24).reshape((2, 3, 4)) + assert_equal(insert(a, 1, a[:,:, 3], axis=-1), + insert(a, 1, a[:,:, 3], axis=2)) + assert_equal(insert(a, 1, a[:, 2,:], axis=-2), + insert(a, 1, a[:, 2,:], axis=1)) # invalid axis value - assert_raises(IndexError, insert, a, 1, a[:,2,:], axis=3) - assert_raises(IndexError, insert, a, 1, a[:,2,:], axis=-4) + assert_raises(IndexError, insert, a, 1, a[:, 2,:], axis=3) + assert_raises(IndexError, insert, a, 1, a[:, 2,:], axis=-4) def test_0d(self): # This is an error in the future @@ -236,9 +236,9 @@ class TestInsert(TestCase): a = np.arange(10).view(SubClass) assert_(isinstance(np.insert(a, 0, [0]), SubClass)) assert_(isinstance(np.insert(a, [], []), SubClass)) - assert_(isinstance(np.insert(a, [0,1], [1,2]), SubClass)) - assert_(isinstance(np.insert(a, slice(1,2), [1,2]), SubClass)) - assert_(isinstance(np.insert(a, slice(1,-2), []), SubClass)) + assert_(isinstance(np.insert(a, [0, 1], [1, 2]), SubClass)) + assert_(isinstance(np.insert(a, slice(1, 2), [1, 2]), SubClass)) + assert_(isinstance(np.insert(a, slice(1, -2), []), SubClass)) # This is an error in the future: a = np.array(1).view(SubClass) assert_(isinstance(np.insert(a, 0, [0]), SubClass)) @@ -355,10 +355,10 @@ class TestDiff(TestCase): def test_nd(self): x = 20 * rand(10, 20, 30) - out1 = x[:, :, 1:] - x[:, :, :-1] - out2 = out1[:, :, 1:] - out1[:, :, :-1] - out3 = x[1:, :, :] - x[:-1, :, :] - out4 = out3[1:, :, :] - out3[:-1, :, :] + out1 = x[:,:, 1:] - x[:,:, :-1] + out2 = out1[:,:, 1:] - out1[:,:, :-1] + out3 = x[1:,:,:] - x[:-1,:,:] + out4 = out3[1:,:,:] - out3[:-1,:,:] assert_array_equal(diff(x), out1) assert_array_equal(diff(x, n=2), out2) assert_array_equal(diff(x, axis=0), out3) @@ -368,7 +368,7 @@ class TestDiff(TestCase): class TestDelete(TestCase): def setUp(self): self.a = np.arange(5) - self.nd_a = np.arange(5).repeat(2).reshape(1,5,2) + self.nd_a = np.arange(5).repeat(2).reshape(1, 5, 2) def _check_inverse_of_slicing(self, indices): a_del = delete(self.a, indices) @@ -380,8 +380,8 @@ class TestDelete(TestCase): indices = indices[(indices >= 0) & (indices < 5)] assert_array_equal(setxor1d(a_del, self.a[indices,]), self.a, err_msg=msg) - xor = setxor1d(nd_a_del[0,:,0], self.nd_a[0,indices,0]) - assert_array_equal(xor, self.nd_a[0,:,0], err_msg=msg) + xor = setxor1d(nd_a_del[0,:, 0], self.nd_a[0, indices, 0]) + assert_array_equal(xor, self.nd_a[0,:, 0], err_msg=msg) def test_slices(self): lims = [-6, -2, 0, 1, 2, 4, 5] @@ -394,7 +394,7 @@ class TestDelete(TestCase): def test_fancy(self): # Deprecation/FutureWarning tests should be kept after change. - self._check_inverse_of_slicing(np.array([[0,1],[2,1]])) + self._check_inverse_of_slicing(np.array([[0, 1], [2, 1]])) assert_raises(DeprecationWarning, delete, self.a, [100]) assert_raises(DeprecationWarning, delete, self.a, [-100]) with warnings.catch_warnings(record=True) as w: @@ -422,9 +422,9 @@ class TestDelete(TestCase): a = self.a.view(SubClass) assert_(isinstance(delete(a, 0), SubClass)) assert_(isinstance(delete(a, []), SubClass)) - assert_(isinstance(delete(a, [0,1]), SubClass)) - assert_(isinstance(delete(a, slice(1,2)), SubClass)) - assert_(isinstance(delete(a, slice(1,-2)), SubClass)) + assert_(isinstance(delete(a, [0, 1]), SubClass)) + assert_(isinstance(delete(a, slice(1, 2)), SubClass)) + assert_(isinstance(delete(a, slice(1, -2)), SubClass)) class TestGradient(TestCase): def test_basic(self): @@ -598,7 +598,7 @@ class TestVectorize(TestCase): while _p: res = res*x + _p.pop(0) return res - vpolyval = np.vectorize(mypolyval, excluded=['p',1]) + vpolyval = np.vectorize(mypolyval, excluded=['p', 1]) ans = [3, 6] assert_array_equal(ans, vpolyval(x=[0, 1], p=[1, 2, 3])) assert_array_equal(ans, vpolyval([0, 1], p=[1, 2, 3])) @@ -776,18 +776,18 @@ class TestTrapz(TestCase): wz[0] /= 2 wz[-1] /= 2 - q = x[:, None, None] + y[None, :, None] + z[None, None, :] + q = x[:, None, None] + y[None,:, None] + z[None, None,:] qx = (q * wx[:, None, None]).sum(axis=0) - qy = (q * wy[None, :, None]).sum(axis=1) - qz = (q * wz[None, None, :]).sum(axis=2) + qy = (q * wy[None,:, None]).sum(axis=1) + qz = (q * wz[None, None,:]).sum(axis=2) # n-d `x` r = trapz(q, x=x[:, None, None], axis=0) assert_almost_equal(r, qx) - r = trapz(q, x=y[None, :, None], axis=1) + r = trapz(q, x=y[None,:, None], axis=1) assert_almost_equal(r, qy) - r = trapz(q, x=z[None, None, :], axis=2) + r = trapz(q, x=z[None, None,:], axis=2) assert_almost_equal(r, qz) # 1-d `x` @@ -1052,7 +1052,7 @@ class TestHistogramdd(TestCase): def test_identical_samples(self): x = np.zeros((10, 2), int) hist, edges = histogramdd(x, bins=2) - assert_array_equal(edges[0], np.array([-0.5, 0. , 0.5])) + assert_array_equal(edges[0], np.array([-0.5, 0., 0.5])) def test_empty(self): a, b = histogramdd([[], []], bins=([0, 1], [0, 1])) @@ -1114,23 +1114,23 @@ class TestCheckFinite(TestCase): class TestCorrCoef(TestCase): A = np.array([[ 0.15391142, 0.18045767, 0.14197213], [ 0.70461506, 0.96474128, 0.27906989], - [ 0.9297531 , 0.32296769, 0.19267156]]) - B = np.array([[ 0.10377691, 0.5417086 , 0.49807457], + [ 0.9297531, 0.32296769, 0.19267156]]) + B = np.array([[ 0.10377691, 0.5417086, 0.49807457], [ 0.82872117, 0.77801674, 0.39226705], - [ 0.9314666 , 0.66800209, 0.03538394]]) - res1 = np.array([[ 1. , 0.9379533 , -0.04931983], - [ 0.9379533 , 1. , 0.30007991], + [ 0.9314666, 0.66800209, 0.03538394]]) + res1 = np.array([[ 1., 0.9379533, -0.04931983], + [ 0.9379533, 1., 0.30007991], [-0.04931983, 0.30007991, 1. ]]) - res2 = np.array([[ 1. , 0.9379533 , -0.04931983, + res2 = np.array([[ 1., 0.9379533, -0.04931983, 0.30151751, 0.66318558, 0.51532523], - [ 0.9379533 , 1. , 0.30007991, + [ 0.9379533, 1., 0.30007991, - 0.04781421, 0.88157256, 0.78052386], - [-0.04931983, 0.30007991, 1. , + [-0.04931983, 0.30007991, 1., - 0.96717111, 0.71483595, 0.83053601], [ 0.30151751, -0.04781421, -0.96717111, - 1. , -0.51366032, -0.66173113], + 1., -0.51366032, -0.66173113], [ 0.66318558, 0.88157256, 0.71483595, - - 0.51366032, 1. , 0.98317823], + - 0.51366032, 1., 0.98317823], [ 0.51532523, 0.78052386, 0.83053601, - 0.66173113, 0.98317823, 1. ]]) @@ -1160,10 +1160,10 @@ class TestCov(TestCase): class Test_I0(TestCase): def test_simple(self): assert_almost_equal(i0(0.5), np.array(1.0634833707413234)) - A = np.array([ 0.49842636, 0.6969809 , 0.22011976, 0.0155549]) + A = np.array([ 0.49842636, 0.6969809, 0.22011976, 0.0155549]) assert_almost_equal(i0(A), np.array([ 1.06307822, 1.12518299, 1.01214991, 1.00006049])) - B = np.array([[ 0.827002 , 0.99959078], + B = np.array([[ 0.827002, 0.99959078], [ 0.89694769, 0.39298162], [ 0.37954418, 0.05206293], [ 0.36465447, 0.72446427], @@ -1173,7 +1173,7 @@ class Test_I0(TestCase): [ 1.21147086, 1.0389829 ], [ 1.03633899, 1.00067775], [ 1.03352052, 1.13557954], - [ 1.0588429 , 1.06432317]])) + [ 1.0588429, 1.06432317]])) class TestKaiser(TestCase): @@ -1182,10 +1182,10 @@ class TestKaiser(TestCase): assert_(np.isfinite(kaiser(1, 1.0))) assert_almost_equal(kaiser(2, 1.0), np.array([ 0.78984831, 0.78984831])) assert_almost_equal(kaiser(5, 1.0), - np.array([ 0.78984831, 0.94503323, 1. , + np.array([ 0.78984831, 0.94503323, 1., 0.94503323, 0.78984831])) assert_almost_equal(kaiser(5, 1.56789), - np.array([ 0.58285404, 0.88409679, 1. , + np.array([ 0.58285404, 0.88409679, 1., 0.88409679, 0.58285404])) def test_int_beta(self): diff --git a/numpy/lib/tests/test_index_tricks.py b/numpy/lib/tests/test_index_tricks.py index 01b705b5d..9002331ce 100644 --- a/numpy/lib/tests/test_index_tricks.py +++ b/numpy/lib/tests/test_index_tricks.py @@ -8,42 +8,42 @@ from numpy import ( array, ones, r_, mgrid, unravel_index, zeros, where, class TestRavelUnravelIndex(TestCase): def test_basic(self): - assert_equal(np.unravel_index(2,(2,2)), (1,0)) - assert_equal(np.ravel_multi_index((1,0),(2,2)), 2) - assert_equal(np.unravel_index(254,(17,94)), (2,66)) - assert_equal(np.ravel_multi_index((2,66),(17,94)), 254) - assert_raises(ValueError, np.unravel_index, -1, (2,2)) - assert_raises(TypeError, np.unravel_index, 0.5, (2,2)) - assert_raises(ValueError, np.unravel_index, 4, (2,2)) - assert_raises(ValueError, np.ravel_multi_index, (-3,1), (2,2)) - assert_raises(ValueError, np.ravel_multi_index, (2,1), (2,2)) - assert_raises(ValueError, np.ravel_multi_index, (0,-3), (2,2)) - assert_raises(ValueError, np.ravel_multi_index, (0,2), (2,2)) - assert_raises(TypeError, np.ravel_multi_index, (0.1,0.), (2,2)) - - assert_equal(np.unravel_index((2*3 + 1)*6 + 4, (4,3,6)), [2,1,4]) - assert_equal(np.ravel_multi_index([2,1,4], (4,3,6)), (2*3 + 1)*6 + 4) - - arr = np.array([[3,6,6],[4,5,1]]) - assert_equal(np.ravel_multi_index(arr, (7,6)), [22,41,37]) - assert_equal(np.ravel_multi_index(arr, (7,6), order='F'), [31,41,13]) - assert_equal(np.ravel_multi_index(arr, (4,6), mode='clip'), [22,23,19]) - assert_equal(np.ravel_multi_index(arr, (4,4), mode=('clip','wrap')), - [12,13,13]) - assert_equal(np.ravel_multi_index((3,1,4,1), (6,7,8,9)), 1621) - - assert_equal(np.unravel_index(np.array([22, 41, 37]), (7,6)), - [[3, 6, 6],[4, 5, 1]]) - assert_equal(np.unravel_index(np.array([31, 41, 13]), (7,6), order='F'), + assert_equal(np.unravel_index(2, (2, 2)), (1, 0)) + assert_equal(np.ravel_multi_index((1, 0), (2, 2)), 2) + assert_equal(np.unravel_index(254, (17, 94)), (2, 66)) + assert_equal(np.ravel_multi_index((2, 66), (17, 94)), 254) + assert_raises(ValueError, np.unravel_index, -1, (2, 2)) + assert_raises(TypeError, np.unravel_index, 0.5, (2, 2)) + assert_raises(ValueError, np.unravel_index, 4, (2, 2)) + assert_raises(ValueError, np.ravel_multi_index, (-3, 1), (2, 2)) + assert_raises(ValueError, np.ravel_multi_index, (2, 1), (2, 2)) + assert_raises(ValueError, np.ravel_multi_index, (0, -3), (2, 2)) + assert_raises(ValueError, np.ravel_multi_index, (0, 2), (2, 2)) + assert_raises(TypeError, np.ravel_multi_index, (0.1, 0.), (2, 2)) + + assert_equal(np.unravel_index((2*3 + 1)*6 + 4, (4, 3, 6)), [2, 1, 4]) + assert_equal(np.ravel_multi_index([2, 1, 4], (4, 3, 6)), (2*3 + 1)*6 + 4) + + arr = np.array([[3, 6, 6], [4, 5, 1]]) + assert_equal(np.ravel_multi_index(arr, (7, 6)), [22, 41, 37]) + assert_equal(np.ravel_multi_index(arr, (7, 6), order='F'), [31, 41, 13]) + assert_equal(np.ravel_multi_index(arr, (4, 6), mode='clip'), [22, 23, 19]) + assert_equal(np.ravel_multi_index(arr, (4, 4), mode=('clip', 'wrap')), + [12, 13, 13]) + assert_equal(np.ravel_multi_index((3, 1, 4, 1), (6, 7, 8, 9)), 1621) + + assert_equal(np.unravel_index(np.array([22, 41, 37]), (7, 6)), [[3, 6, 6], [4, 5, 1]]) - assert_equal(np.unravel_index(1621, (6,7,8,9)), [3,1,4,1]) + assert_equal(np.unravel_index(np.array([31, 41, 13]), (7, 6), order='F'), + [[3, 6, 6], [4, 5, 1]]) + assert_equal(np.unravel_index(1621, (6, 7, 8, 9)), [3, 1, 4, 1]) def test_dtypes(self): # Test with different data types for dtype in [np.int16, np.uint16, np.int32, np.uint32, np.int64, np.uint64]: - coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0]], dtype=dtype) - shape = (5,8) + coords = np.array([[1, 0, 1, 2, 3, 4], [1, 6, 1, 3, 2, 0]], dtype=dtype) + shape = (5, 8) uncoords = 8*coords[0]+coords[1] assert_equal(np.ravel_multi_index(coords, shape), uncoords) assert_equal(coords, np.unravel_index(uncoords, shape)) @@ -51,9 +51,9 @@ class TestRavelUnravelIndex(TestCase): assert_equal(np.ravel_multi_index(coords, shape, order='F'), uncoords) assert_equal(coords, np.unravel_index(uncoords, shape, order='F')) - coords = np.array([[1,0,1,2,3,4],[1,6,1,3,2,0],[1,3,1,0,9,5]], + coords = np.array([[1, 0, 1, 2, 3, 4], [1, 6, 1, 3, 2, 0], [1, 3, 1, 0, 9, 5]], dtype=dtype) - shape = (5,8,10) + shape = (5, 8, 10) uncoords = 10*(8*coords[0]+coords[1])+coords[2] assert_equal(np.ravel_multi_index(coords, shape), uncoords) assert_equal(coords, np.unravel_index(uncoords, shape)) @@ -63,12 +63,12 @@ class TestRavelUnravelIndex(TestCase): def test_clipmodes(self): # Test clipmodes - assert_equal(np.ravel_multi_index([5,1,-1,2], (4,3,7,12), mode='wrap'), - np.ravel_multi_index([1,1,6,2], (4,3,7,12))) - assert_equal(np.ravel_multi_index([5,1,-1,2], (4,3,7,12), - mode=('wrap','raise','clip','raise')), - np.ravel_multi_index([1,1,0,2], (4,3,7,12))) - assert_raises(ValueError, np.ravel_multi_index, [5,1,-1,2], (4,3,7,12)) + assert_equal(np.ravel_multi_index([5, 1, -1, 2], (4, 3, 7, 12), mode='wrap'), + np.ravel_multi_index([1, 1, 6, 2], (4, 3, 7, 12))) + assert_equal(np.ravel_multi_index([5, 1, -1, 2], (4, 3, 7, 12), + mode=('wrap', 'raise', 'clip', 'raise')), + np.ravel_multi_index([1, 1, 0, 2], (4, 3, 7, 12))) + assert_raises(ValueError, np.ravel_multi_index, [5, 1, -1, 2], (4, 3, 7, 12)) class TestGrid(TestCase): def test_basic(self): @@ -77,63 +77,63 @@ class TestGrid(TestCase): assert_(a.shape == (10,)) assert_(b.shape == (20,)) assert_(a[0] == -1) - assert_almost_equal(a[-1],1) + assert_almost_equal(a[-1], 1) assert_(b[0] == -1) - assert_almost_equal(b[1]-b[0],0.1,11) - assert_almost_equal(b[-1],b[0]+19*0.1,11) - assert_almost_equal(a[1]-a[0],2.0/9.0,11) + assert_almost_equal(b[1]-b[0], 0.1, 11) + assert_almost_equal(b[-1], b[0]+19*0.1, 11) + assert_almost_equal(a[1]-a[0], 2.0/9.0, 11) def test_linspace_equivalence(self): - y,st = np.linspace(2,10,retstep=1) - assert_almost_equal(st,8/49.0) - assert_array_almost_equal(y,mgrid[2:10:50j],13) + y, st = np.linspace(2, 10, retstep=1) + assert_almost_equal(st, 8/49.0) + assert_array_almost_equal(y, mgrid[2:10:50j], 13) def test_nd(self): - c = mgrid[-1:1:10j,-2:2:10j] - d = mgrid[-1:1:0.1,-2:2:0.2] - assert_(c.shape == (2,10,10)) - assert_(d.shape == (2,20,20)) - assert_array_equal(c[0][0,:],-ones(10,'d')) - assert_array_equal(c[1][:,0],-2*ones(10,'d')) - assert_array_almost_equal(c[0][-1,:],ones(10,'d'),11) - assert_array_almost_equal(c[1][:,-1],2*ones(10,'d'),11) - assert_array_almost_equal(d[0,1,:]-d[0,0,:], 0.1*ones(20,'d'),11) - assert_array_almost_equal(d[1,:,1]-d[1,:,0], 0.2*ones(20,'d'),11) + c = mgrid[-1:1:10j, -2:2:10j] + d = mgrid[-1:1:0.1, -2:2:0.2] + assert_(c.shape == (2, 10, 10)) + assert_(d.shape == (2, 20, 20)) + assert_array_equal(c[0][0,:], -ones(10, 'd')) + assert_array_equal(c[1][:, 0], -2*ones(10, 'd')) + assert_array_almost_equal(c[0][-1,:], ones(10, 'd'), 11) + assert_array_almost_equal(c[1][:, -1], 2*ones(10, 'd'), 11) + assert_array_almost_equal(d[0, 1,:]-d[0, 0,:], 0.1*ones(20, 'd'), 11) + assert_array_almost_equal(d[1,:, 1]-d[1,:, 0], 0.2*ones(20, 'd'), 11) class TestConcatenator(TestCase): def test_1d(self): - assert_array_equal(r_[1,2,3,4,5,6],array([1,2,3,4,5,6])) + assert_array_equal(r_[1, 2, 3, 4, 5, 6], array([1, 2, 3, 4, 5, 6])) b = ones(5) - c = r_[b,0,0,b] - assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1]) + c = r_[b, 0, 0, b] + assert_array_equal(c, [1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]) def test_mixed_type(self): g = r_[10.1, 1:10] assert_(g.dtype == 'f8') def test_more_mixed_type(self): - g = r_[-10.1, array([1]), array([2,3,4]), 10.0] + g = r_[-10.1, array([1]), array([2, 3, 4]), 10.0] assert_(g.dtype == 'f8') def test_2d(self): - b = rand(5,5) - c = rand(5,5) - d = r_['1',b,c] # append columns - assert_(d.shape == (5,10)) - assert_array_equal(d[:,:5],b) - assert_array_equal(d[:,5:],c) - d = r_[b,c] - assert_(d.shape == (10,5)) - assert_array_equal(d[:5,:],b) - assert_array_equal(d[5:,:],c) + b = rand(5, 5) + c = rand(5, 5) + d = r_['1', b, c] # append columns + assert_(d.shape == (5, 10)) + assert_array_equal(d[:, :5], b) + assert_array_equal(d[:, 5:], c) + d = r_[b, c] + assert_(d.shape == (10, 5)) + assert_array_equal(d[:5,:], b) + assert_array_equal(d[5:,:], c) class TestNdenumerate(TestCase): def test_basic(self): - a = array([[1,2], [3,4]]) + a = array([[1, 2], [3, 4]]) assert_equal(list(ndenumerate(a)), - [((0,0), 1), ((0,1), 2), ((1,0), 3), ((1,1), 4)]) + [((0, 0), 1), ((0, 1), 2), ((1, 0), 3), ((1, 1), 4)]) class TestIndexExpression(TestCase): @@ -144,17 +144,17 @@ class TestIndexExpression(TestCase): assert_equal(a[:-1], a[index_exp[:-1]]) def test_simple_1(self): - a = np.random.rand(4,5,6) + a = np.random.rand(4, 5, 6) - assert_equal(a[:,:3,[1,2]], a[index_exp[:,:3,[1,2]]]) - assert_equal(a[:,:3,[1,2]], a[s_[:,:3,[1,2]]]) + assert_equal(a[:, :3, [1, 2]], a[index_exp[:, :3, [1, 2]]]) + assert_equal(a[:, :3, [1, 2]], a[s_[:, :3, [1, 2]]]) def test_c_(): - a = np.c_[np.array([[1,2,3]]), 0, 0, np.array([[4,5,6]])] + a = np.c_[np.array([[1, 2, 3]]), 0, 0, np.array([[4, 5, 6]])] assert_equal(a, [[1, 2, 3, 0, 0, 4, 5, 6]]) def test_fill_diagonal(): - a = zeros((3, 3),int) + a = zeros((3, 3), int) fill_diagonal(a, 5) yield (assert_array_equal, a, array([[5, 0, 0], @@ -162,7 +162,7 @@ def test_fill_diagonal(): [0, 0, 5]])) #Test tall matrix - a = zeros((10, 3),int) + a = zeros((10, 3), int) fill_diagonal(a, 5) yield (assert_array_equal, a, array([[5, 0, 0], @@ -177,7 +177,7 @@ def test_fill_diagonal(): [0, 0, 0]])) #Test tall matrix wrap - a = zeros((10, 3),int) + a = zeros((10, 3), int) fill_diagonal(a, 5, True) yield (assert_array_equal, a, array([[5, 0, 0], @@ -192,7 +192,7 @@ def test_fill_diagonal(): [0, 5, 0]])) #Test wide matrix - a = zeros((3, 10),int) + a = zeros((3, 10), int) fill_diagonal(a, 5) yield (assert_array_equal, a, array([[5, 0, 0, 0, 0, 0, 0, 0, 0, 0], @@ -223,7 +223,7 @@ def test_diag_indices(): d3 = diag_indices(2, 3) # And use it to set the diagonal of a zeros array to 1: - a = zeros((2, 2, 2),int) + a = zeros((2, 2, 2), int) a[d3] = 1 yield (assert_array_equal, a, array([[[1, 0], diff --git a/numpy/lib/tests/test_io.py b/numpy/lib/tests/test_io.py index 4095dd813..af06cd45e 100644 --- a/numpy/lib/tests/test_io.py +++ b/numpy/lib/tests/test_io.py @@ -583,7 +583,7 @@ class TestLoadTxt(TestCase): ('block', int, (2, 2, 3))]) x = np.loadtxt(c, dtype=dt) a = np.array([('aaaa', 1.0, 8.0, - [[[1, 2, 3], [4, 5, 6]],[[7, 8, 9], [10, 11, 12]]])], + [[[1, 2, 3], [4, 5, 6]], [[7, 8, 9], [10, 11, 12]]])], dtype=dt) assert_array_equal(x, a) @@ -1554,7 +1554,7 @@ M 33 21.99 def test_gft_using_filename(self): # Test that we can load data from a filename as well as a file object - wanted = np.arange(6).reshape((2,3)) + wanted = np.arange(6).reshape((2, 3)) if sys.version_info[0] >= 3: # python 3k is known to fail for '\r' linesep = ('\n', '\r\n') diff --git a/numpy/lib/tests/test_nanfunctions.py b/numpy/lib/tests/test_nanfunctions.py index 93a5ef855..292ffdf7a 100644 --- a/numpy/lib/tests/test_nanfunctions.py +++ b/numpy/lib/tests/test_nanfunctions.py @@ -17,7 +17,7 @@ _ndat = np.array( [[ 0.6244, np.nan, 0.2692, 0.0116, np.nan, 0.1170], [ 0.5351, 0.9403, np.nan, 0.2100, 0.4759, 0.2833], [ np.nan, np.nan, np.nan, 0.1042, np.nan, 0.5954], - [ 0.161 , np.nan, np.nan, 0.1859, 0.3146, np.nan]] + [ 0.161, np.nan, np.nan, 0.1859, 0.3146, np.nan]] ) # rows of _ndat with nans removed @@ -131,7 +131,7 @@ class TestNanFunctions_ArgminArgmax(TestCase): assert_(issubclass(w[0].category, NanWarning)) def test_empty(self): - mat = np.zeros((0,3)) + mat = np.zeros((0, 3)) for f in self.nanfuncs: for axis in [0, None]: assert_raises(ValueError, f, mat, axis=axis) @@ -253,7 +253,7 @@ class TestNanFunctions_Sum(TestCase): assert_(len(w) == 0, 'warning raised') def test_empty(self): - mat = np.zeros((0,3)) + mat = np.zeros((0, 3)) if np.__version__[:3] < '1.9': tgt = [np.nan]*3 res = nansum(mat, axis=0) @@ -398,7 +398,7 @@ class TestNanFunctions_MeanVarStd(TestCase): assert_(issubclass(w[0].category, NanWarning)) def test_empty(self): - mat = np.zeros((0,3)) + mat = np.zeros((0, 3)) for f in self.nanfuncs: for axis in [0, None]: with warnings.catch_warnings(record=True) as w: diff --git a/numpy/lib/tests/test_polynomial.py b/numpy/lib/tests/test_polynomial.py index fa166b7f1..617419eee 100644 --- a/numpy/lib/tests/test_polynomial.py +++ b/numpy/lib/tests/test_polynomial.py @@ -86,29 +86,29 @@ class TestDocs(TestCase): return rundocs() def test_roots(self): - assert_array_equal(np.roots([1,0,0]), [0,0]) + assert_array_equal(np.roots([1, 0, 0]), [0, 0]) def test_str_leading_zeros(self): - p = np.poly1d([4,3,2,1]) + p = np.poly1d([4, 3, 2, 1]) p[3] = 0 assert_equal(str(p), " 2\n" "3 x + 2 x + 1") - p = np.poly1d([1,2]) + p = np.poly1d([1, 2]) p[0] = 0 p[1] = 0 assert_equal(str(p), " \n0") def test_polyfit(self) : c = np.array([3., 2., 1.]) - x = np.linspace(0,2,7) - y = np.polyval(c,x) - err = [1,-1,1,-1,1,-1,1] - weights = np.arange(8,1,-1)**2/7.0 + x = np.linspace(0, 2, 7) + y = np.polyval(c, x) + err = [1, -1, 1, -1, 1, -1, 1] + weights = np.arange(8, 1, -1)**2/7.0 # check 1D case - m, cov = np.polyfit(x,y+err,2,cov=True) + m, cov = np.polyfit(x, y+err, 2, cov=True) est = [3.8571, 0.2857, 1.619] assert_almost_equal(est, m, decimal=4) val0 = [[2.9388, -5.8776, 1.6327], @@ -116,7 +116,7 @@ class TestDocs(TestCase): [1.6327, -4.2449, 2.3220]] assert_almost_equal(val0, cov, decimal=4) - m2, cov2 = np.polyfit(x,y+err,2,w=weights,cov=True) + m2, cov2 = np.polyfit(x, y+err, 2, w=weights, cov=True) assert_almost_equal([4.8927, -1.0177, 1.7768], m2, decimal=4) val = [[ 8.7929, -10.0103, 0.9756], [-10.0103, 13.6134, -1.8178], @@ -124,19 +124,19 @@ class TestDocs(TestCase): assert_almost_equal(val, cov2, decimal=4) # check 2D (n,1) case - y = y[:,np.newaxis] - c = c[:,np.newaxis] - assert_almost_equal(c, np.polyfit(x,y,2)) + y = y[:, np.newaxis] + c = c[:, np.newaxis] + assert_almost_equal(c, np.polyfit(x, y, 2)) # check 2D (n,2) case - yy = np.concatenate((y,y), axis=1) - cc = np.concatenate((c,c), axis=1) - assert_almost_equal(cc, np.polyfit(x,yy,2)) + yy = np.concatenate((y, y), axis=1) + cc = np.concatenate((c, c), axis=1) + assert_almost_equal(cc, np.polyfit(x, yy, 2)) - m, cov = np.polyfit(x,yy + np.array(err)[:,np.newaxis],2,cov=True) - assert_almost_equal(est, m[:,0], decimal=4) - assert_almost_equal(est, m[:,1], decimal=4) - assert_almost_equal(val0, cov[:,:,0], decimal=4) - assert_almost_equal(val0, cov[:,:,1], decimal=4) + m, cov = np.polyfit(x, yy + np.array(err)[:, np.newaxis], 2, cov=True) + assert_almost_equal(est, m[:, 0], decimal=4) + assert_almost_equal(est, m[:, 1], decimal=4) + assert_almost_equal(val0, cov[:,:, 0], decimal=4) + assert_almost_equal(val0, cov[:,:, 1], decimal=4) def test_objects(self): from decimal import Decimal @@ -153,14 +153,14 @@ class TestDocs(TestCase): def test_complex(self): p = np.poly1d([3j, 2j, 1j]) p2 = p.integ() - assert_((p2.coeffs == [1j,1j,1j,0]).all()) + assert_((p2.coeffs == [1j, 1j, 1j, 0]).all()) p2 = p.deriv() - assert_((p2.coeffs == [6j,2j]).all()) + assert_((p2.coeffs == [6j, 2j]).all()) def test_integ_coeffs(self): - p = np.poly1d([3,2,1]) - p2 = p.integ(3, k=[9,7,6]) - assert_((p2.coeffs == [1/4./5.,1/3./4.,1/2./3.,9/1./2.,7,6]).all()) + p = np.poly1d([3, 2, 1]) + p2 = p.integ(3, k=[9, 7, 6]) + assert_((p2.coeffs == [1/4./5., 1/3./4., 1/2./3., 9/1./2., 7, 6]).all()) def test_zero_dims(self): try: diff --git a/numpy/lib/tests/test_recfunctions.py b/numpy/lib/tests/test_recfunctions.py index ef22ca413..b175bcb64 100644 --- a/numpy/lib/tests/test_recfunctions.py +++ b/numpy/lib/tests/test_recfunctions.py @@ -660,13 +660,13 @@ class TestJoinBy2(TestCase): assert_equal(test, control) def test_two_keys_two_vars(self): - a = np.array(list(zip(np.tile([10,11],5),np.repeat(np.arange(5),2), - np.arange(50, 60), np.arange(10,20))), - dtype=[('k', int), ('a', int), ('b', int),('c',int)]) + a = np.array(list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2), + np.arange(50, 60), np.arange(10, 20))), + dtype=[('k', int), ('a', int), ('b', int), ('c', int)]) - b = np.array(list(zip(np.tile([10,11],5),np.repeat(np.arange(5),2), - np.arange(65, 75), np.arange(0,10))), - dtype=[('k', int), ('a', int), ('b', int), ('c',int)]) + b = np.array(list(zip(np.tile([10, 11], 5), np.repeat(np.arange(5), 2), + np.arange(65, 75), np.arange(0, 10))), + dtype=[('k', int), ('a', int), ('b', int), ('c', int)]) control = np.array([(10, 0, 50, 65, 10, 0), (11, 0, 51, 66, 11, 1), (10, 1, 52, 67, 12, 2), (11, 1, 53, 68, 13, 3), @@ -675,7 +675,7 @@ class TestJoinBy2(TestCase): (10, 4, 58, 73, 18, 8), (11, 4, 59, 74, 19, 9)], dtype=[('k', int), ('a', int), ('b1', int), ('b2', int), ('c1', int), ('c2', int)]) - test = join_by(['a','k'], a, b, r1postfix='1', r2postfix='2', jointype='inner') + test = join_by(['a', 'k'], a, b, r1postfix='1', r2postfix='2', jointype='inner') assert_equal(test.dtype, control.dtype) assert_equal(test, control) diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py index 1e9bacdf5..67808bd39 100644 --- a/numpy/lib/tests/test_regression.py +++ b/numpy/lib/tests/test_regression.py @@ -12,22 +12,22 @@ rlevel = 1 class TestRegression(TestCase): def test_poly1d(self,level=rlevel): """Ticket #28""" - assert_equal(np.poly1d([1]) - np.poly1d([1,0]), - np.poly1d([-1,1])) + assert_equal(np.poly1d([1]) - np.poly1d([1, 0]), + np.poly1d([-1, 1])) def test_cov_parameters(self,level=rlevel): """Ticket #91""" - x = np.random.random((3,3)) + x = np.random.random((3, 3)) y = x.copy() np.cov(x, rowvar=1) np.cov(y, rowvar=0) - assert_array_equal(x,y) + assert_array_equal(x, y) def test_mem_digitize(self,level=rlevel): """Ticket #95""" for i in range(100): - np.digitize([1,2,3,4],[1,3]) - np.digitize([0,1,2,3,4],[1,3]) + np.digitize([1, 2, 3, 4], [1, 3]) + np.digitize([0, 1, 2, 3, 4], [1, 3]) def test_unique_zero_sized(self,level=rlevel): """Ticket #205""" @@ -36,51 +36,51 @@ class TestRegression(TestCase): def test_mem_vectorise(self, level=rlevel): """Ticket #325""" vt = np.vectorize(lambda *args: args) - vt(np.zeros((1,2,1)), np.zeros((2,1,1)), np.zeros((1,1,2))) - vt(np.zeros((1,2,1)), np.zeros((2,1,1)), np.zeros((1,1,2)), np.zeros((2,2))) + vt(np.zeros((1, 2, 1)), np.zeros((2, 1, 1)), np.zeros((1, 1, 2))) + vt(np.zeros((1, 2, 1)), np.zeros((2, 1, 1)), np.zeros((1, 1, 2)), np.zeros((2, 2))) def test_mgrid_single_element(self, level=rlevel): """Ticket #339""" - assert_array_equal(np.mgrid[0:0:1j],[0]) - assert_array_equal(np.mgrid[0:0],[]) + assert_array_equal(np.mgrid[0:0:1j], [0]) + assert_array_equal(np.mgrid[0:0], []) def test_refcount_vectorize(self, level=rlevel): """Ticket #378""" - def p(x,y): return 123 + def p(x, y): return 123 v = np.vectorize(p) _assert_valid_refcount(v) def test_poly1d_nan_roots(self, level=rlevel): """Ticket #396""" - p = np.poly1d([np.nan,np.nan,1], r=0) - self.assertRaises(np.linalg.LinAlgError,getattr,p,"r") + p = np.poly1d([np.nan, np.nan, 1], r=0) + self.assertRaises(np.linalg.LinAlgError, getattr, p, "r") def test_mem_polymul(self, level=rlevel): """Ticket #448""" - np.polymul([],[1.]) + np.polymul([], [1.]) def test_mem_string_concat(self, level=rlevel): """Ticket #469""" x = np.array([]) - np.append(x,'asdasd\tasdasd') + np.append(x, 'asdasd\tasdasd') def test_poly_div(self, level=rlevel): """Ticket #553""" - u = np.poly1d([1,2,3]) - v = np.poly1d([1,2,3,4,5]) - q,r = np.polydiv(u,v) + u = np.poly1d([1, 2, 3]) + v = np.poly1d([1, 2, 3, 4, 5]) + q, r = np.polydiv(u, v) assert_equal(q*v + r, u) def test_poly_eq(self, level=rlevel): """Ticket #554""" - x = np.poly1d([1,2,3]) - y = np.poly1d([3,4]) + x = np.poly1d([1, 2, 3]) + y = np.poly1d([3, 4]) assert_(x != y) assert_(x == x) def test_mem_insert(self, level=rlevel): """Ticket #572""" - np.lib.place(1,1,1) + np.lib.place(1, 1, 1) def test_polyfit_build(self): """Ticket #628""" @@ -108,16 +108,16 @@ class TestRegression(TestCase): """Make polydiv work for complex types""" msg = "Wrong type, should be complex" x = np.ones(3, dtype=np.complex) - q,r = np.polydiv(x,x) + q, r = np.polydiv(x, x) assert_(q.dtype == np.complex, msg) msg = "Wrong type, should be float" x = np.ones(3, dtype=np.int) - q,r = np.polydiv(x,x) + q, r = np.polydiv(x, x) assert_(q.dtype == np.float, msg) def test_histogramdd_too_many_bins(self) : """Ticket 928.""" - assert_raises(ValueError, np.histogramdd, np.ones((1,10)), bins=2**10) + assert_raises(ValueError, np.histogramdd, np.ones((1, 10)), bins=2**10) def test_polyint_type(self) : """Ticket #944""" @@ -144,20 +144,20 @@ class TestRegression(TestCase): def dp(): n = 3 a = np.ones((n,)*5) - i = np.random.randint(0,n,size=thesize) - a[np.ix_(i,i,i,i,i)] = 0 + i = np.random.randint(0, n, size=thesize) + a[np.ix_(i, i, i, i, i)] = 0 def dp2(): n = 3 a = np.ones((n,)*5) - i = np.random.randint(0,n,size=thesize) - g = a[np.ix_(i,i,i,i,i)] + i = np.random.randint(0, n, size=thesize) + g = a[np.ix_(i, i, i, i, i)] self.assertRaises(ValueError, dp) self.assertRaises(ValueError, dp2) def test_void_coercion(self, level=rlevel): - dt = np.dtype([('a','f4'),('b','i4')]) - x = np.zeros((1,),dt) - assert_(np.r_[x,x].dtype == dt) + dt = np.dtype([('a', 'f4'), ('b', 'i4')]) + x = np.zeros((1,), dt) + assert_(np.r_[x, x].dtype == dt) def test_who_with_0dim_array(self, level=rlevel) : """ticket #1243""" @@ -194,9 +194,9 @@ class TestRegression(TestCase): """Ticket #1676""" from numpy.lib.recfunctions import append_fields F = False - base = np.array([1,2,3], dtype=np.int32) + base = np.array([1, 2, 3], dtype=np.int32) data = np.eye(3).astype(np.int32) - names = ['a','b','c'] + names = ['a', 'b', 'c'] dlist = [np.float64, np.int32, np.int32] try: a = append_fields(base, names, data, dlist) @@ -214,17 +214,17 @@ class TestRegression(TestCase): x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) assert_equal(x, np.array([((0, 1), (2, 3))], dtype=dt)) - dt = [("a", [("a", 'u1', (1,3)), ("b", 'u1')])] + dt = [("a", [("a", 'u1', (1, 3)), ("b", 'u1')])] x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) - assert_equal(x, np.array([(((0,1,2), 3),)], dtype=dt)) + assert_equal(x, np.array([(((0, 1, 2), 3),)], dtype=dt)) - dt = [("a", 'u1', (2,2))] + dt = [("a", 'u1', (2, 2))] x = np.loadtxt(StringIO("0 1 2 3"), dtype=dt) assert_equal(x, np.array([(((0, 1), (2, 3)),)], dtype=dt)) - dt = [("a", 'u1', (2,3,2))] + dt = [("a", 'u1', (2, 3, 2))] x = np.loadtxt(StringIO("0 1 2 3 4 5 6 7 8 9 10 11"), dtype=dt) - data = [((((0,1), (2,3), (4,5)), ((6,7), (8,9), (10,11))),)] + data = [((((0, 1), (2, 3), (4, 5)), ((6, 7), (8, 9), (10, 11))),)] assert_equal(x, np.array(data, dtype=dt)) def test_nansum_with_boolean(self): diff --git a/numpy/lib/tests/test_shape_base.py b/numpy/lib/tests/test_shape_base.py index a92ddde83..157e1beb3 100644 --- a/numpy/lib/tests/test_shape_base.py +++ b/numpy/lib/tests/test_shape_base.py @@ -7,133 +7,133 @@ from numpy import matrix, asmatrix class TestApplyAlongAxis(TestCase): def test_simple(self): - a = ones((20,10),'d') - assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1])) + a = ones((20, 10), 'd') + assert_array_equal(apply_along_axis(len, 0, a), len(a)*ones(shape(a)[1])) def test_simple101(self,level=11): - a = ones((10,101),'d') - assert_array_equal(apply_along_axis(len,0,a),len(a)*ones(shape(a)[1])) + a = ones((10, 101), 'd') + assert_array_equal(apply_along_axis(len, 0, a), len(a)*ones(shape(a)[1])) def test_3d(self): - a = arange(27).reshape((3,3,3)) - assert_array_equal(apply_along_axis(sum,0,a), - [[27,30,33],[36,39,42],[45,48,51]]) + a = arange(27).reshape((3, 3, 3)) + assert_array_equal(apply_along_axis(sum, 0, a), + [[27, 30, 33], [36, 39, 42], [45, 48, 51]]) class TestApplyOverAxes(TestCase): def test_simple(self): - a = arange(24).reshape(2,3,4) - aoa_a = apply_over_axes(sum, a, [0,2]) - assert_array_equal(aoa_a, array([[[60],[92],[124]]])) + a = arange(24).reshape(2, 3, 4) + aoa_a = apply_over_axes(sum, a, [0, 2]) + assert_array_equal(aoa_a, array([[[60], [92], [124]]])) class TestArraySplit(TestCase): def test_integer_0_split(self): a = arange(10) try: - res = array_split(a,0) + res = array_split(a, 0) assert_(0) # it should have thrown a value error except ValueError: pass def test_integer_split(self): a = arange(10) - res = array_split(a,1) + res = array_split(a, 1) desired = [arange(10)] - compare_results(res,desired) - - res = array_split(a,2) - desired = [arange(5),arange(5,10)] - compare_results(res,desired) - - res = array_split(a,3) - desired = [arange(4),arange(4,7),arange(7,10)] - compare_results(res,desired) - - res = array_split(a,4) - desired = [arange(3),arange(3,6),arange(6,8),arange(8,10)] - compare_results(res,desired) - - res = array_split(a,5) - desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,10)] - compare_results(res,desired) - - res = array_split(a,6) - desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,9), - arange(9,10)] - compare_results(res,desired) - - res = array_split(a,7) - desired = [arange(2),arange(2,4),arange(4,6),arange(6,7),arange(7,8), - arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,8) - desired = [arange(2),arange(2,4),arange(4,5),arange(5,6),arange(6,7), - arange(7,8), arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,9) - desired = [arange(2),arange(2,3),arange(3,4),arange(4,5),arange(5,6), - arange(6,7), arange(7,8), arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,10) - desired = [arange(1),arange(1,2),arange(2,3),arange(3,4), - arange(4,5),arange(5,6), arange(6,7), arange(7,8), - arange(8,9), arange(9,10)] - compare_results(res,desired) - - res = array_split(a,11) - desired = [arange(1),arange(1,2),arange(2,3),arange(3,4), - arange(4,5),arange(5,6), arange(6,7), arange(7,8), - arange(8,9), arange(9,10),array([])] - compare_results(res,desired) + compare_results(res, desired) + + res = array_split(a, 2) + desired = [arange(5), arange(5, 10)] + compare_results(res, desired) + + res = array_split(a, 3) + desired = [arange(4), arange(4, 7), arange(7, 10)] + compare_results(res, desired) + + res = array_split(a, 4) + desired = [arange(3), arange(3, 6), arange(6, 8), arange(8, 10)] + compare_results(res, desired) + + res = array_split(a, 5) + desired = [arange(2), arange(2, 4), arange(4, 6), arange(6, 8), arange(8, 10)] + compare_results(res, desired) + + res = array_split(a, 6) + desired = [arange(2), arange(2, 4), arange(4, 6), arange(6, 8), arange(8, 9), + arange(9, 10)] + compare_results(res, desired) + + res = array_split(a, 7) + desired = [arange(2), arange(2, 4), arange(4, 6), arange(6, 7), arange(7, 8), + arange(8, 9), arange(9, 10)] + compare_results(res, desired) + + res = array_split(a, 8) + desired = [arange(2), arange(2, 4), arange(4, 5), arange(5, 6), arange(6, 7), + arange(7, 8), arange(8, 9), arange(9, 10)] + compare_results(res, desired) + + res = array_split(a, 9) + desired = [arange(2), arange(2, 3), arange(3, 4), arange(4, 5), arange(5, 6), + arange(6, 7), arange(7, 8), arange(8, 9), arange(9, 10)] + compare_results(res, desired) + + res = array_split(a, 10) + desired = [arange(1), arange(1, 2), arange(2, 3), arange(3, 4), + arange(4, 5), arange(5, 6), arange(6, 7), arange(7, 8), + arange(8, 9), arange(9, 10)] + compare_results(res, desired) + + res = array_split(a, 11) + desired = [arange(1), arange(1, 2), arange(2, 3), arange(3, 4), + arange(4, 5), arange(5, 6), arange(6, 7), arange(7, 8), + arange(8, 9), arange(9, 10), array([])] + compare_results(res, desired) def test_integer_split_2D_rows(self): - a = array([arange(10),arange(10)]) - res = array_split(a,3,axis=0) - desired = [array([arange(10)]),array([arange(10)]),array([])] - compare_results(res,desired) + a = array([arange(10), arange(10)]) + res = array_split(a, 3, axis=0) + desired = [array([arange(10)]), array([arange(10)]), array([])] + compare_results(res, desired) def test_integer_split_2D_cols(self): - a = array([arange(10),arange(10)]) - res = array_split(a,3,axis=-1) - desired = [array([arange(4),arange(4)]), - array([arange(4,7),arange(4,7)]), - array([arange(7,10),arange(7,10)])] - compare_results(res,desired) + a = array([arange(10), arange(10)]) + res = array_split(a, 3, axis=-1) + desired = [array([arange(4), arange(4)]), + array([arange(4, 7), arange(4, 7)]), + array([arange(7, 10), arange(7, 10)])] + compare_results(res, desired) def test_integer_split_2D_default(self): """ This will fail if we change default axis """ - a = array([arange(10),arange(10)]) - res = array_split(a,3) - desired = [array([arange(10)]),array([arange(10)]),array([])] - compare_results(res,desired) + a = array([arange(10), arange(10)]) + res = array_split(a, 3) + desired = [array([arange(10)]), array([arange(10)]), array([])] + compare_results(res, desired) #perhaps should check higher dimensions def test_index_split_simple(self): a = arange(10) - indices = [1,5,7] - res = array_split(a,indices,axis=-1) - desired = [arange(0,1),arange(1,5),arange(5,7),arange(7,10)] - compare_results(res,desired) + indices = [1, 5, 7] + res = array_split(a, indices, axis=-1) + desired = [arange(0, 1), arange(1, 5), arange(5, 7), arange(7, 10)] + compare_results(res, desired) def test_index_split_low_bound(self): a = arange(10) - indices = [0,5,7] - res = array_split(a,indices,axis=-1) - desired = [array([]),arange(0,5),arange(5,7),arange(7,10)] - compare_results(res,desired) + indices = [0, 5, 7] + res = array_split(a, indices, axis=-1) + desired = [array([]), arange(0, 5), arange(5, 7), arange(7, 10)] + compare_results(res, desired) def test_index_split_high_bound(self): a = arange(10) - indices = [0,5,7,10,12] - res = array_split(a,indices,axis=-1) - desired = [array([]),arange(0,5),arange(5,7),arange(7,10), - array([]),array([])] - compare_results(res,desired) + indices = [0, 5, 7, 10, 12] + res = array_split(a, indices, axis=-1) + desired = [array([]), arange(0, 5), arange(5, 7), arange(7, 10), + array([]), array([])] + compare_results(res, desired) class TestSplit(TestCase): @@ -143,14 +143,14 @@ class TestSplit(TestCase): *""" def test_equal_split(self): a = arange(10) - res = split(a,2) - desired = [arange(5),arange(5,10)] - compare_results(res,desired) + res = split(a, 2) + desired = [arange(5), arange(5, 10)] + compare_results(res, desired) def test_unequal_split(self): a = arange(10) try: - res = split(a,3) + res = split(a, 3) assert_(0) # should raise an error except ValueError: pass @@ -159,27 +159,27 @@ class TestSplit(TestCase): class TestDstack(TestCase): def test_0D_array(self): a = array(1); b = array(2); - res=dstack([a,b]) - desired = array([[[1,2]]]) - assert_array_equal(res,desired) + res=dstack([a, b]) + desired = array([[[1, 2]]]) + assert_array_equal(res, desired) def test_1D_array(self): a = array([1]); b = array([2]); - res=dstack([a,b]) - desired = array([[[1,2]]]) - assert_array_equal(res,desired) + res=dstack([a, b]) + desired = array([[[1, 2]]]) + assert_array_equal(res, desired) def test_2D_array(self): - a = array([[1],[2]]); b = array([[1],[2]]); - res=dstack([a,b]) - desired = array([[[1,1]],[[2,2,]]]) - assert_array_equal(res,desired) + a = array([[1], [2]]); b = array([[1], [2]]); + res=dstack([a, b]) + desired = array([[[1, 1]], [[2, 2,]]]) + assert_array_equal(res, desired) def test_2D_array2(self): - a = array([1,2]); b = array([1,2]); - res=dstack([a,b]) - desired = array([[[1,1],[2,2]]]) - assert_array_equal(res,desired) + a = array([1, 2]); b = array([1, 2]); + res=dstack([a, b]) + desired = array([[[1, 1], [2, 2]]]) + assert_array_equal(res, desired) """ array_split has more comprehensive test of splitting. only do simple test on hsplit, vsplit, and dsplit @@ -190,75 +190,75 @@ class TestHsplit(TestCase): def test_0D_array(self): a= array(1) try: - hsplit(a,2) + hsplit(a, 2) assert_(0) except ValueError: pass def test_1D_array(self): - a= array([1,2,3,4]) - res = hsplit(a,2) - desired = [array([1,2]),array([3,4])] - compare_results(res,desired) + a= array([1, 2, 3, 4]) + res = hsplit(a, 2) + desired = [array([1, 2]), array([3, 4])] + compare_results(res, desired) def test_2D_array(self): - a= array([[1,2,3,4], - [1,2,3,4]]) - res = hsplit(a,2) - desired = [array([[1,2],[1,2]]),array([[3,4],[3,4]])] - compare_results(res,desired) + a= array([[1, 2, 3, 4], + [1, 2, 3, 4]]) + res = hsplit(a, 2) + desired = [array([[1, 2], [1, 2]]), array([[3, 4], [3, 4]])] + compare_results(res, desired) class TestVsplit(TestCase): """ only testing for integer splits. """ def test_1D_array(self): - a= array([1,2,3,4]) + a= array([1, 2, 3, 4]) try: - vsplit(a,2) + vsplit(a, 2) assert_(0) except ValueError: pass def test_2D_array(self): - a= array([[1,2,3,4], - [1,2,3,4]]) - res = vsplit(a,2) - desired = [array([[1,2,3,4]]),array([[1,2,3,4]])] - compare_results(res,desired) + a= array([[1, 2, 3, 4], + [1, 2, 3, 4]]) + res = vsplit(a, 2) + desired = [array([[1, 2, 3, 4]]), array([[1, 2, 3, 4]])] + compare_results(res, desired) class TestDsplit(TestCase): """ only testing for integer splits. """ def test_2D_array(self): - a= array([[1,2,3,4], - [1,2,3,4]]) + a= array([[1, 2, 3, 4], + [1, 2, 3, 4]]) try: - dsplit(a,2) + dsplit(a, 2) assert_(0) except ValueError: pass def test_3D_array(self): - a= array([[[1,2,3,4], - [1,2,3,4]], - [[1,2,3,4], - [1,2,3,4]]]) - res = dsplit(a,2) - desired = [array([[[1,2],[1,2]],[[1,2],[1,2]]]), - array([[[3,4],[3,4]],[[3,4],[3,4]]])] - compare_results(res,desired) + a= array([[[1, 2, 3, 4], + [1, 2, 3, 4]], + [[1, 2, 3, 4], + [1, 2, 3, 4]]]) + res = dsplit(a, 2) + desired = [array([[[1, 2], [1, 2]], [[1, 2], [1, 2]]]), + array([[[3, 4], [3, 4]], [[3, 4], [3, 4]]])] + compare_results(res, desired) class TestSqueeze(TestCase): def test_basic(self): - a = rand(20,10,10,1,1) - b = rand(20,1,10,1,20) - c = rand(1,1,20,10) - assert_array_equal(squeeze(a),reshape(a,(20,10,10))) - assert_array_equal(squeeze(b),reshape(b,(20,10,20))) - assert_array_equal(squeeze(c),reshape(c,(20,10))) + a = rand(20, 10, 10, 1, 1) + b = rand(20, 1, 10, 1, 20) + c = rand(1, 1, 20, 10) + assert_array_equal(squeeze(a), reshape(a, (20, 10, 10))) + assert_array_equal(squeeze(b), reshape(b, (20, 10, 20))) + assert_array_equal(squeeze(c), reshape(c, (20, 10))) # Squeezing to 0-dim should still give an ndarray a = [[[1.5]]] @@ -270,44 +270,44 @@ class TestSqueeze(TestCase): class TestKron(TestCase): def test_return_type(self): - a = ones([2,2]) + a = ones([2, 2]) m = asmatrix(a) - assert_equal(type(kron(a,a)), ndarray) - assert_equal(type(kron(m,m)), matrix) - assert_equal(type(kron(a,m)), matrix) - assert_equal(type(kron(m,a)), matrix) + assert_equal(type(kron(a, a)), ndarray) + assert_equal(type(kron(m, m)), matrix) + assert_equal(type(kron(a, m)), matrix) + assert_equal(type(kron(m, a)), matrix) class myarray(ndarray): __array_priority__ = 0.0 ma = myarray(a.shape, a.dtype, a.data) - assert_equal(type(kron(a,a)), ndarray) - assert_equal(type(kron(ma,ma)), myarray) - assert_equal(type(kron(a,ma)), ndarray) - assert_equal(type(kron(ma,a)), myarray) + assert_equal(type(kron(a, a)), ndarray) + assert_equal(type(kron(ma, ma)), myarray) + assert_equal(type(kron(a, ma)), ndarray) + assert_equal(type(kron(ma, a)), myarray) class TestTile(TestCase): def test_basic(self): - a = array([0,1,2]) - b = [[1,2],[3,4]] - assert_equal(tile(a,2), [0,1,2,0,1,2]) - assert_equal(tile(a,(2,2)), [[0,1,2,0,1,2],[0,1,2,0,1,2]]) - assert_equal(tile(a,(1,2)), [[0,1,2,0,1,2]]) - assert_equal(tile(b, 2), [[1,2,1,2],[3,4,3,4]]) - assert_equal(tile(b,(2,1)),[[1,2],[3,4],[1,2],[3,4]]) - assert_equal(tile(b,(2,2)),[[1,2,1,2],[3,4,3,4], - [1,2,1,2],[3,4,3,4]]) + a = array([0, 1, 2]) + b = [[1, 2], [3, 4]] + assert_equal(tile(a, 2), [0, 1, 2, 0, 1, 2]) + assert_equal(tile(a, (2, 2)), [[0, 1, 2, 0, 1, 2], [0, 1, 2, 0, 1, 2]]) + assert_equal(tile(a, (1, 2)), [[0, 1, 2, 0, 1, 2]]) + assert_equal(tile(b, 2), [[1, 2, 1, 2], [3, 4, 3, 4]]) + assert_equal(tile(b, (2, 1)), [[1, 2], [3, 4], [1, 2], [3, 4]]) + assert_equal(tile(b, (2, 2)), [[1, 2, 1, 2], [3, 4, 3, 4], + [1, 2, 1, 2], [3, 4, 3, 4]]) def test_empty(self): a = array([[[]]]) - d = tile(a,(3,2,5)).shape - assert_equal(d,(3,2,0)) + d = tile(a, (3, 2, 5)).shape + assert_equal(d, (3, 2, 0)) def test_kroncompare(self): import numpy.random as nr - reps=[(2,),(1,2),(2,1),(2,2),(2,3,2),(3,2)] - shape=[(3,),(2,3),(3,4,3),(3,2,3),(4,3,2,4),(2,2)] + reps=[(2,), (1, 2), (2, 1), (2, 2), (2, 3, 2), (3, 2)] + shape=[(3,), (2, 3), (3, 4, 3), (3, 2, 3), (4, 3, 2, 4), (2, 2)] for s in shape: - b = nr.randint(0,10,size=s) + b = nr.randint(0, 10, size=s) for r in reps: a = ones(r, b.dtype) large = tile(b, r) @@ -331,9 +331,9 @@ class TestMayShareMemory(TestCase): # Utility -def compare_results(res,desired): +def compare_results(res, desired): for i in range(len(desired)): - assert_array_equal(res[i],desired[i]) + assert_array_equal(res[i], desired[i]) if __name__ == "__main__": diff --git a/numpy/lib/tests/test_stride_tricks.py b/numpy/lib/tests/test_stride_tricks.py index f815b247f..5d06e0a8c 100644 --- a/numpy/lib/tests/test_stride_tricks.py +++ b/numpy/lib/tests/test_stride_tricks.py @@ -52,10 +52,10 @@ def test_same(): assert_array_equal(y, by) def test_one_off(): - x = np.array([[1,2,3]]) - y = np.array([[1],[2],[3]]) + x = np.array([[1, 2, 3]]) + y = np.array([[1], [2], [3]]) bx, by = broadcast_arrays(x, y) - bx0 = np.array([[1,2,3],[1,2,3],[1,2,3]]) + bx0 = np.array([[1, 2, 3], [1, 2, 3], [1, 2, 3]]) by0 = bx0.T assert_array_equal(bx0, bx) assert_array_equal(by0, by) @@ -67,13 +67,13 @@ def test_same_input_shapes(): (), (1,), (3,), - (0,1), - (0,3), - (1,0), - (3,0), - (1,3), - (3,1), - (3,3), + (0, 1), + (0, 3), + (1, 0), + (3, 0), + (1, 3), + (3, 1), + (3, 3), ] for shape in data: input_shapes = [shape] @@ -92,18 +92,18 @@ def test_two_compatible_by_ones_input_shapes(): """ data = [ [[(1,), (3,)], (3,)], - [[(1,3), (3,3)], (3,3)], - [[(3,1), (3,3)], (3,3)], - [[(1,3), (3,1)], (3,3)], - [[(1,1), (3,3)], (3,3)], - [[(1,1), (1,3)], (1,3)], - [[(1,1), (3,1)], (3,1)], - [[(1,0), (0,0)], (0,0)], - [[(0,1), (0,0)], (0,0)], - [[(1,0), (0,1)], (0,0)], - [[(1,1), (0,0)], (0,0)], - [[(1,1), (1,0)], (1,0)], - [[(1,1), (0,1)], (0,1)], + [[(1, 3), (3, 3)], (3, 3)], + [[(3, 1), (3, 3)], (3, 3)], + [[(1, 3), (3, 1)], (3, 3)], + [[(1, 1), (3, 3)], (3, 3)], + [[(1, 1), (1, 3)], (1, 3)], + [[(1, 1), (3, 1)], (3, 1)], + [[(1, 0), (0, 0)], (0, 0)], + [[(0, 1), (0, 0)], (0, 0)], + [[(1, 0), (0, 1)], (0, 0)], + [[(1, 1), (0, 0)], (0, 0)], + [[(1, 1), (1, 0)], (1, 0)], + [[(1, 1), (0, 1)], (0, 1)], ] for input_shapes, expected_shape in data: assert_shapes_correct(input_shapes, expected_shape) @@ -116,25 +116,25 @@ def test_two_compatible_by_prepending_ones_input_shapes(): """ data = [ [[(), (3,)], (3,)], - [[(3,), (3,3)], (3,3)], - [[(3,), (3,1)], (3,3)], - [[(1,), (3,3)], (3,3)], - [[(), (3,3)], (3,3)], - [[(1,1), (3,)], (1,3)], - [[(1,), (3,1)], (3,1)], - [[(1,), (1,3)], (1,3)], - [[(), (1,3)], (1,3)], - [[(), (3,1)], (3,1)], + [[(3,), (3, 3)], (3, 3)], + [[(3,), (3, 1)], (3, 3)], + [[(1,), (3, 3)], (3, 3)], + [[(), (3, 3)], (3, 3)], + [[(1, 1), (3,)], (1, 3)], + [[(1,), (3, 1)], (3, 1)], + [[(1,), (1, 3)], (1, 3)], + [[(), (1, 3)], (1, 3)], + [[(), (3, 1)], (3, 1)], [[(), (0,)], (0,)], - [[(0,), (0,0)], (0,0)], - [[(0,), (0,1)], (0,0)], - [[(1,), (0,0)], (0,0)], - [[(), (0,0)], (0,0)], - [[(1,1), (0,)], (1,0)], - [[(1,), (0,1)], (0,1)], - [[(1,), (1,0)], (1,0)], - [[(), (1,0)], (1,0)], - [[(), (0,1)], (0,1)], + [[(0,), (0, 0)], (0, 0)], + [[(0,), (0, 1)], (0, 0)], + [[(1,), (0, 0)], (0, 0)], + [[(), (0, 0)], (0, 0)], + [[(1, 1), (0,)], (1, 0)], + [[(1,), (0, 1)], (0, 1)], + [[(1,), (1, 0)], (1, 0)], + [[(), (1, 0)], (1, 0)], + [[(), (0, 1)], (0, 1)], ] for input_shapes, expected_shape in data: assert_shapes_correct(input_shapes, expected_shape) @@ -146,9 +146,9 @@ def test_incompatible_shapes_raise_valueerror(): """ data = [ [(3,), (4,)], - [(2,3), (2,)], + [(2, 3), (2,)], [(3,), (3,), (4,)], - [(1,3,4), (2,3,3)], + [(1, 3, 4), (2, 3, 3)], ] for input_shapes in data: assert_incompatible_shapes_raise(input_shapes) @@ -160,38 +160,38 @@ def test_same_as_ufunc(): """ data = [ [[(1,), (3,)], (3,)], - [[(1,3), (3,3)], (3,3)], - [[(3,1), (3,3)], (3,3)], - [[(1,3), (3,1)], (3,3)], - [[(1,1), (3,3)], (3,3)], - [[(1,1), (1,3)], (1,3)], - [[(1,1), (3,1)], (3,1)], - [[(1,0), (0,0)], (0,0)], - [[(0,1), (0,0)], (0,0)], - [[(1,0), (0,1)], (0,0)], - [[(1,1), (0,0)], (0,0)], - [[(1,1), (1,0)], (1,0)], - [[(1,1), (0,1)], (0,1)], + [[(1, 3), (3, 3)], (3, 3)], + [[(3, 1), (3, 3)], (3, 3)], + [[(1, 3), (3, 1)], (3, 3)], + [[(1, 1), (3, 3)], (3, 3)], + [[(1, 1), (1, 3)], (1, 3)], + [[(1, 1), (3, 1)], (3, 1)], + [[(1, 0), (0, 0)], (0, 0)], + [[(0, 1), (0, 0)], (0, 0)], + [[(1, 0), (0, 1)], (0, 0)], + [[(1, 1), (0, 0)], (0, 0)], + [[(1, 1), (1, 0)], (1, 0)], + [[(1, 1), (0, 1)], (0, 1)], [[(), (3,)], (3,)], - [[(3,), (3,3)], (3,3)], - [[(3,), (3,1)], (3,3)], - [[(1,), (3,3)], (3,3)], - [[(), (3,3)], (3,3)], - [[(1,1), (3,)], (1,3)], - [[(1,), (3,1)], (3,1)], - [[(1,), (1,3)], (1,3)], - [[(), (1,3)], (1,3)], - [[(), (3,1)], (3,1)], + [[(3,), (3, 3)], (3, 3)], + [[(3,), (3, 1)], (3, 3)], + [[(1,), (3, 3)], (3, 3)], + [[(), (3, 3)], (3, 3)], + [[(1, 1), (3,)], (1, 3)], + [[(1,), (3, 1)], (3, 1)], + [[(1,), (1, 3)], (1, 3)], + [[(), (1, 3)], (1, 3)], + [[(), (3, 1)], (3, 1)], [[(), (0,)], (0,)], - [[(0,), (0,0)], (0,0)], - [[(0,), (0,1)], (0,0)], - [[(1,), (0,0)], (0,0)], - [[(), (0,0)], (0,0)], - [[(1,1), (0,)], (1,0)], - [[(1,), (0,1)], (0,1)], - [[(1,), (1,0)], (1,0)], - [[(), (1,0)], (1,0)], - [[(), (0,1)], (0,1)], + [[(0,), (0, 0)], (0, 0)], + [[(0,), (0, 1)], (0, 0)], + [[(1,), (0, 0)], (0, 0)], + [[(), (0, 0)], (0, 0)], + [[(1, 1), (0,)], (1, 0)], + [[(1,), (0, 1)], (0, 1)], + [[(1,), (1, 0)], (1, 0)], + [[(), (1, 0)], (1, 0)], + [[(), (0, 1)], (0, 1)], ] for input_shapes, expected_shape in data: assert_same_as_ufunc(input_shapes[0], input_shapes[1], diff --git a/numpy/lib/tests/test_twodim_base.py b/numpy/lib/tests/test_twodim_base.py index 7e590c1db..4ec5c34a2 100644 --- a/numpy/lib/tests/test_twodim_base.py +++ b/numpy/lib/tests/test_twodim_base.py @@ -14,46 +14,46 @@ from numpy.compat import asbytes, asbytes_nested def get_mat(n): data = arange(n) - data = add.outer(data,data) + data = add.outer(data, data) return data class TestEye(TestCase): def test_basic(self): - assert_equal(eye(4),array([[1,0,0,0], - [0,1,0,0], - [0,0,1,0], - [0,0,0,1]])) - assert_equal(eye(4,dtype='f'),array([[1,0,0,0], - [0,1,0,0], - [0,0,1,0], - [0,0,0,1]],'f')) - assert_equal(eye(3) == 1, eye(3,dtype=bool)) + assert_equal(eye(4), array([[1, 0, 0, 0], + [0, 1, 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1]])) + assert_equal(eye(4, dtype='f'), array([[1, 0, 0, 0], + [0, 1, 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1]], 'f')) + assert_equal(eye(3) == 1, eye(3, dtype=bool)) def test_diag(self): - assert_equal(eye(4,k=1),array([[0,1,0,0], - [0,0,1,0], - [0,0,0,1], - [0,0,0,0]])) - assert_equal(eye(4,k=-1),array([[0,0,0,0], - [1,0,0,0], - [0,1,0,0], - [0,0,1,0]])) + assert_equal(eye(4, k=1), array([[0, 1, 0, 0], + [0, 0, 1, 0], + [0, 0, 0, 1], + [0, 0, 0, 0]])) + assert_equal(eye(4, k=-1), array([[0, 0, 0, 0], + [1, 0, 0, 0], + [0, 1, 0, 0], + [0, 0, 1, 0]])) def test_2d(self): - assert_equal(eye(4,3),array([[1,0,0], - [0,1,0], - [0,0,1], - [0,0,0]])) - assert_equal(eye(3,4),array([[1,0,0,0], - [0,1,0,0], - [0,0,1,0]])) + assert_equal(eye(4, 3), array([[1, 0, 0], + [0, 1, 0], + [0, 0, 1], + [0, 0, 0]])) + assert_equal(eye(3, 4), array([[1, 0, 0, 0], + [0, 1, 0, 0], + [0, 0, 1, 0]])) def test_diag2d(self): - assert_equal(eye(3,4,k=2),array([[0,0,1,0], - [0,0,0,1], - [0,0,0,0]])) - assert_equal(eye(4,3,k=-2),array([[0,0,0], - [0,0,0], - [1,0,0], - [0,1,0]])) + assert_equal(eye(3, 4, k=2), array([[0, 0, 1, 0], + [0, 0, 0, 1], + [0, 0, 0, 0]])) + assert_equal(eye(4, 3, k=-2), array([[0, 0, 0], + [0, 0, 0], + [1, 0, 0], + [0, 1, 0]])) def test_eye_bounds(self): assert_equal(eye(2, 2, 1), [[0, 1], [0, 0]]) @@ -93,7 +93,7 @@ class TestDiag(TestCase): vals = (100 * get_mat(5) + 1).astype('l') b = zeros((5,)) for k in range(5): - b[k] = vals[k,k] + b[k] = vals[k, k] assert_equal(diag(vals), b) b = b * 0 for k in range(3): @@ -123,61 +123,61 @@ class TestFliplr(TestCase): def test_basic(self): self.assertRaises(ValueError, fliplr, ones(4)) a = get_mat(4) - b = a[:,::-1] - assert_equal(fliplr(a),b) - a = [[0,1,2], - [3,4,5]] - b = [[2,1,0], - [5,4,3]] - assert_equal(fliplr(a),b) + b = a[:, ::-1] + assert_equal(fliplr(a), b) + a = [[0, 1, 2], + [3, 4, 5]] + b = [[2, 1, 0], + [5, 4, 3]] + assert_equal(fliplr(a), b) class TestFlipud(TestCase): def test_basic(self): a = get_mat(4) b = a[::-1,:] - assert_equal(flipud(a),b) - a = [[0,1,2], - [3,4,5]] - b = [[3,4,5], - [0,1,2]] - assert_equal(flipud(a),b) + assert_equal(flipud(a), b) + a = [[0, 1, 2], + [3, 4, 5]] + b = [[3, 4, 5], + [0, 1, 2]] + assert_equal(flipud(a), b) class TestRot90(TestCase): def test_basic(self): self.assertRaises(ValueError, rot90, ones(4)) - a = [[0,1,2], - [3,4,5]] - b1 = [[2,5], - [1,4], - [0,3]] - b2 = [[5,4,3], - [2,1,0]] - b3 = [[3,0], - [4,1], - [5,2]] - b4 = [[0,1,2], - [3,4,5]] - - for k in range(-3,13,4): - assert_equal(rot90(a,k=k),b1) - for k in range(-2,13,4): - assert_equal(rot90(a,k=k),b2) - for k in range(-1,13,4): - assert_equal(rot90(a,k=k),b3) - for k in range(0,13,4): - assert_equal(rot90(a,k=k),b4) + a = [[0, 1, 2], + [3, 4, 5]] + b1 = [[2, 5], + [1, 4], + [0, 3]] + b2 = [[5, 4, 3], + [2, 1, 0]] + b3 = [[3, 0], + [4, 1], + [5, 2]] + b4 = [[0, 1, 2], + [3, 4, 5]] + + for k in range(-3, 13, 4): + assert_equal(rot90(a, k=k), b1) + for k in range(-2, 13, 4): + assert_equal(rot90(a, k=k), b2) + for k in range(-1, 13, 4): + assert_equal(rot90(a, k=k), b3) + for k in range(0, 13, 4): + assert_equal(rot90(a, k=k), b4) def test_axes(self): - a = ones((50,40,3)) - assert_equal(rot90(a).shape,(40,50,3)) + a = ones((50, 40, 3)) + assert_equal(rot90(a).shape, (40, 50, 3)) class TestHistogram2d(TestCase): def test_simple(self): x = array([ 0.41702200, 0.72032449, 0.00011437481, 0.302332573, 0.146755891]) y = array([ 0.09233859, 0.18626021, 0.34556073, 0.39676747, 0.53881673]) - xedges = np.linspace(0,1,10) - yedges = np.linspace(0,1,10) + xedges = np.linspace(0, 1, 10) + yedges = np.linspace(0, 1, 10) H = histogram2d(x, y, (xedges, yedges))[0] answer = array([[0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0], @@ -191,40 +191,40 @@ class TestHistogram2d(TestCase): assert_array_equal(H.T, answer) H = histogram2d(x, y, xedges)[0] assert_array_equal(H.T, answer) - H,xedges,yedges = histogram2d(list(range(10)),list(range(10))) - assert_array_equal(H, eye(10,10)) - assert_array_equal(xedges, np.linspace(0,9,11)) - assert_array_equal(yedges, np.linspace(0,9,11)) + H, xedges, yedges = histogram2d(list(range(10)), list(range(10))) + assert_array_equal(H, eye(10, 10)) + assert_array_equal(xedges, np.linspace(0, 9, 11)) + assert_array_equal(yedges, np.linspace(0, 9, 11)) def test_asym(self): x = array([1, 1, 2, 3, 4, 4, 4, 5]) y = array([1, 3, 2, 0, 1, 2, 3, 4]) - H, xed, yed = histogram2d(x,y, (6, 5), range = [[0,6],[0,5]], normed=True) - answer = array([[0.,0,0,0,0], - [0,1,0,1,0], - [0,0,1,0,0], - [1,0,0,0,0], - [0,1,1,1,0], - [0,0,0,0,1]]) + H, xed, yed = histogram2d(x, y, (6, 5), range = [[0, 6], [0, 5]], normed=True) + answer = array([[0., 0, 0, 0, 0], + [0, 1, 0, 1, 0], + [0, 0, 1, 0, 0], + [1, 0, 0, 0, 0], + [0, 1, 1, 1, 0], + [0, 0, 0, 0, 1]]) assert_array_almost_equal(H, answer/8., 3) - assert_array_equal(xed, np.linspace(0,6,7)) - assert_array_equal(yed, np.linspace(0,5,6)) + assert_array_equal(xed, np.linspace(0, 6, 7)) + assert_array_equal(yed, np.linspace(0, 5, 6)) def test_norm(self): - x = array([1,2,3,1,2,3,1,2,3]) - y = array([1,1,1,2,2,2,3,3,3]) - H, xed, yed = histogram2d(x,y,[[1,2,3,5], [1,2,3,5]], normed=True) - answer=array([[1,1,.5], - [1,1,.5], - [.5,.5,.25]])/9. + x = array([1, 2, 3, 1, 2, 3, 1, 2, 3]) + y = array([1, 1, 1, 2, 2, 2, 3, 3, 3]) + H, xed, yed = histogram2d(x, y, [[1, 2, 3, 5], [1, 2, 3, 5]], normed=True) + answer=array([[1, 1, .5], + [1, 1, .5], + [.5, .5, .25]])/9. assert_array_almost_equal(H, answer, 3) def test_all_outliers(self): r = rand(100)+1. - H, xed, yed = histogram2d(r, r, (4, 5), range=([0,1], [0,1])) + H, xed, yed = histogram2d(r, r, (4, 5), range=([0, 1], [0, 1])) assert_array_equal(H, 0) def test_empty(self): - a, edge1, edge2 = histogram2d([],[], bins=([0,1],[0,1])) + a, edge1, edge2 = histogram2d([], [], bins=([0, 1], [0, 1])) assert_array_max_ulp(a, array([[ 0.]])) a, edge1, edge2 = histogram2d([], [], bins=4) @@ -233,11 +233,11 @@ class TestHistogram2d(TestCase): class TestTri(TestCase): def test_dtype(self): - out = array([[1,0,0], - [1,1,0], - [1,1,1]]) - assert_array_equal(tri(3),out) - assert_array_equal(tri(3,dtype=bool),out.astype(bool)) + out = array([[1, 0, 0], + [1, 1, 0], + [1, 1, 1]]) + assert_array_equal(tri(3), out) + assert_array_equal(tri(3, dtype=bool), out.astype(bool)) def test_tril_triu(): @@ -327,15 +327,15 @@ class TestTriuIndices(object): class TestTrilIndicesFrom(object): def test_exceptions(self): assert_raises(ValueError, tril_indices_from, np.ones((2,))) - assert_raises(ValueError, tril_indices_from, np.ones((2,2,2))) - assert_raises(ValueError, tril_indices_from, np.ones((2,3))) + assert_raises(ValueError, tril_indices_from, np.ones((2, 2, 2))) + assert_raises(ValueError, tril_indices_from, np.ones((2, 3))) class TestTriuIndicesFrom(object): def test_exceptions(self): assert_raises(ValueError, triu_indices_from, np.ones((2,))) - assert_raises(ValueError, triu_indices_from, np.ones((2,2,2))) - assert_raises(ValueError, triu_indices_from, np.ones((2,3))) + assert_raises(ValueError, triu_indices_from, np.ones((2, 2, 2))) + assert_raises(ValueError, triu_indices_from, np.ones((2, 3))) if __name__ == "__main__": diff --git a/numpy/lib/tests/test_type_check.py b/numpy/lib/tests/test_type_check.py index 8b01a974a..3ca093e16 100644 --- a/numpy/lib/tests/test_type_check.py +++ b/numpy/lib/tests/test_type_check.py @@ -20,11 +20,11 @@ def assert_all(x): class TestCommonType(TestCase): def test_basic(self): - ai32 = array([[1,2],[3,4]], dtype=int32) - af32 = array([[1,2],[3,4]], dtype=float32) - af64 = array([[1,2],[3,4]], dtype=float64) - acs = array([[1+5j,2+6j],[3+7j,4+8j]], dtype=csingle) - acd = array([[1+5j,2+6j],[3+7j,4+8j]], dtype=cdouble) + ai32 = array([[1, 2], [3, 4]], dtype=int32) + af32 = array([[1, 2], [3, 4]], dtype=float32) + af64 = array([[1, 2], [3, 4]], dtype=float64) + acs = array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=csingle) + acd = array([[1+5j, 2+6j], [3+7j, 4+8j]], dtype=cdouble) assert_(common_type(af32) == float32) assert_(common_type(af64) == float64) assert_(common_type(acs) == csingle) @@ -36,50 +36,50 @@ class TestMintypecode(TestCase): def test_default_1(self): for itype in '1bcsuwil': - assert_equal(mintypecode(itype),'d') - assert_equal(mintypecode('f'),'f') - assert_equal(mintypecode('d'),'d') - assert_equal(mintypecode('F'),'F') - assert_equal(mintypecode('D'),'D') + assert_equal(mintypecode(itype), 'd') + assert_equal(mintypecode('f'), 'f') + assert_equal(mintypecode('d'), 'd') + assert_equal(mintypecode('F'), 'F') + assert_equal(mintypecode('D'), 'D') def test_default_2(self): for itype in '1bcsuwil': - assert_equal(mintypecode(itype+'f'),'f') - assert_equal(mintypecode(itype+'d'),'d') - assert_equal(mintypecode(itype+'F'),'F') - assert_equal(mintypecode(itype+'D'),'D') - assert_equal(mintypecode('ff'),'f') - assert_equal(mintypecode('fd'),'d') - assert_equal(mintypecode('fF'),'F') - assert_equal(mintypecode('fD'),'D') - assert_equal(mintypecode('df'),'d') - assert_equal(mintypecode('dd'),'d') + assert_equal(mintypecode(itype+'f'), 'f') + assert_equal(mintypecode(itype+'d'), 'd') + assert_equal(mintypecode(itype+'F'), 'F') + assert_equal(mintypecode(itype+'D'), 'D') + assert_equal(mintypecode('ff'), 'f') + assert_equal(mintypecode('fd'), 'd') + assert_equal(mintypecode('fF'), 'F') + assert_equal(mintypecode('fD'), 'D') + assert_equal(mintypecode('df'), 'd') + assert_equal(mintypecode('dd'), 'd') #assert_equal(mintypecode('dF',savespace=1),'F') - assert_equal(mintypecode('dF'),'D') - assert_equal(mintypecode('dD'),'D') - assert_equal(mintypecode('Ff'),'F') + assert_equal(mintypecode('dF'), 'D') + assert_equal(mintypecode('dD'), 'D') + assert_equal(mintypecode('Ff'), 'F') #assert_equal(mintypecode('Fd',savespace=1),'F') - assert_equal(mintypecode('Fd'),'D') - assert_equal(mintypecode('FF'),'F') - assert_equal(mintypecode('FD'),'D') - assert_equal(mintypecode('Df'),'D') - assert_equal(mintypecode('Dd'),'D') - assert_equal(mintypecode('DF'),'D') - assert_equal(mintypecode('DD'),'D') + assert_equal(mintypecode('Fd'), 'D') + assert_equal(mintypecode('FF'), 'F') + assert_equal(mintypecode('FD'), 'D') + assert_equal(mintypecode('Df'), 'D') + assert_equal(mintypecode('Dd'), 'D') + assert_equal(mintypecode('DF'), 'D') + assert_equal(mintypecode('DD'), 'D') def test_default_3(self): - assert_equal(mintypecode('fdF'),'D') + assert_equal(mintypecode('fdF'), 'D') #assert_equal(mintypecode('fdF',savespace=1),'F') - assert_equal(mintypecode('fdD'),'D') - assert_equal(mintypecode('fFD'),'D') - assert_equal(mintypecode('dFD'),'D') - - assert_equal(mintypecode('ifd'),'d') - assert_equal(mintypecode('ifF'),'F') - assert_equal(mintypecode('ifD'),'D') - assert_equal(mintypecode('idF'),'D') + assert_equal(mintypecode('fdD'), 'D') + assert_equal(mintypecode('fFD'), 'D') + assert_equal(mintypecode('dFD'), 'D') + + assert_equal(mintypecode('ifd'), 'd') + assert_equal(mintypecode('ifF'), 'F') + assert_equal(mintypecode('ifD'), 'D') + assert_equal(mintypecode('idF'), 'D') #assert_equal(mintypecode('idF',savespace=1),'F') - assert_equal(mintypecode('idD'),'D') + assert_equal(mintypecode('idD'), 'D') class TestIsscalar(TestCase): @@ -97,72 +97,72 @@ class TestReal(TestCase): def test_real(self): y = rand(10,) - assert_array_equal(y,real(y)) + assert_array_equal(y, real(y)) def test_cmplx(self): y = rand(10,)+1j*rand(10,) - assert_array_equal(y.real,real(y)) + assert_array_equal(y.real, real(y)) class TestImag(TestCase): def test_real(self): y = rand(10,) - assert_array_equal(0,imag(y)) + assert_array_equal(0, imag(y)) def test_cmplx(self): y = rand(10,)+1j*rand(10,) - assert_array_equal(y.imag,imag(y)) + assert_array_equal(y.imag, imag(y)) class TestIscomplex(TestCase): def test_fail(self): - z = array([-1,0,1]) + z = array([-1, 0, 1]) res = iscomplex(z) - assert_(not sometrue(res,axis=0)) + assert_(not sometrue(res, axis=0)) def test_pass(self): - z = array([-1j,1,0]) + z = array([-1j, 1, 0]) res = iscomplex(z) - assert_array_equal(res,[1,0,0]) + assert_array_equal(res, [1, 0, 0]) class TestIsreal(TestCase): def test_pass(self): - z = array([-1,0,1j]) + z = array([-1, 0, 1j]) res = isreal(z) - assert_array_equal(res,[1,1,0]) + assert_array_equal(res, [1, 1, 0]) def test_fail(self): - z = array([-1j,1,0]) + z = array([-1j, 1, 0]) res = isreal(z) - assert_array_equal(res,[0,1,1]) + assert_array_equal(res, [0, 1, 1]) class TestIscomplexobj(TestCase): def test_basic(self): - z = array([-1,0,1]) + z = array([-1, 0, 1]) assert_(not iscomplexobj(z)) - z = array([-1j,0,-1]) + z = array([-1j, 0, -1]) assert_(iscomplexobj(z)) class TestIsrealobj(TestCase): def test_basic(self): - z = array([-1,0,1]) + z = array([-1, 0, 1]) assert_(isrealobj(z)) - z = array([-1j,0,-1]) + z = array([-1j, 0, -1]) assert_(not isrealobj(z)) class TestIsnan(TestCase): def test_goodvalues(self): - z = array((-1.,0.,1.)) + z = array((-1., 0., 1.)) res = isnan(z) == 0 - assert_all(alltrue(res,axis=0)) + assert_all(alltrue(res, axis=0)) def test_posinf(self): with errstate(divide='ignore'): @@ -193,9 +193,9 @@ class TestIsnan(TestCase): class TestIsfinite(TestCase): def test_goodvalues(self): - z = array((-1.,0.,1.)) + z = array((-1., 0., 1.)) res = isfinite(z) == 1 - assert_all(alltrue(res,axis=0)) + assert_all(alltrue(res, axis=0)) def test_posinf(self): with errstate(divide='ignore', invalid='ignore'): @@ -226,9 +226,9 @@ class TestIsfinite(TestCase): class TestIsinf(TestCase): def test_goodvalues(self): - z = array((-1.,0.,1.)) + z = array((-1., 0., 1.)) res = isinf(z) == 0 - assert_all(alltrue(res,axis=0)) + assert_all(alltrue(res, axis=0)) def test_posinf(self): with errstate(divide='ignore', invalid='ignore'): @@ -259,7 +259,7 @@ class TestIsposinf(TestCase): def test_generic(self): with errstate(divide='ignore', invalid='ignore'): - vals = isposinf(array((-1.,0,1))/0.) + vals = isposinf(array((-1., 0, 1))/0.) assert_(vals[0] == 0) assert_(vals[1] == 0) assert_(vals[2] == 1) @@ -269,7 +269,7 @@ class TestIsneginf(TestCase): def test_generic(self): with errstate(divide='ignore', invalid='ignore'): - vals = isneginf(array((-1.,0,1))/0.) + vals = isneginf(array((-1., 0, 1))/0.) assert_(vals[0] == 1) assert_(vals[1] == 0) assert_(vals[2] == 0) @@ -279,7 +279,7 @@ class TestNanToNum(TestCase): def test_generic(self): with errstate(divide='ignore', invalid='ignore'): - vals = nan_to_num(array((-1.,0,1))/0.) + vals = nan_to_num(array((-1., 0, 1))/0.) assert_all(vals[0] < -1e10) and assert_all(isfinite(vals[0])) assert_(vals[1] == 0) assert_all(vals[2] > 1e10) and assert_all(isfinite(vals[2])) @@ -319,19 +319,19 @@ class TestRealIfClose(TestCase): a = rand(10) b = real_if_close(a+1e-15j) assert_all(isrealobj(b)) - assert_array_equal(a,b) + assert_array_equal(a, b) b = real_if_close(a+1e-7j) assert_all(iscomplexobj(b)) - b = real_if_close(a+1e-7j,tol=1e-6) + b = real_if_close(a+1e-7j, tol=1e-6) assert_all(isrealobj(b)) class TestArrayConversion(TestCase): def test_asfarray(self): - a = asfarray(array([1,2,3])) - assert_equal(a.__class__,ndarray) - assert_(issubdtype(a.dtype,float)) + a = asfarray(array([1, 2, 3])) + assert_equal(a.__class__, ndarray) + assert_(issubdtype(a.dtype, float)) if __name__ == "__main__": run_module_suite() diff --git a/numpy/lib/tests/test_ufunclike.py b/numpy/lib/tests/test_ufunclike.py index 50f3229e8..31dbdba1a 100644 --- a/numpy/lib/tests/test_ufunclike.py +++ b/numpy/lib/tests/test_ufunclike.py @@ -54,7 +54,7 @@ class TestUfunclike(TestCase): a = nx.array([1.1, -1.1]) m = MyArray(a, metadata='foo') f = ufl.fix(m) - assert_array_equal(f, nx.array([1,-1])) + assert_array_equal(f, nx.array([1, -1])) assert_(isinstance(f, MyArray)) assert_equal(f.metadata, 'foo') diff --git a/numpy/lib/twodim_base.py b/numpy/lib/twodim_base.py index a39f60220..91df1f4f8 100644 --- a/numpy/lib/twodim_base.py +++ b/numpy/lib/twodim_base.py @@ -3,9 +3,9 @@ """ from __future__ import division, absolute_import, print_function -__all__ = ['diag','diagflat','eye','fliplr','flipud','rot90','tri','triu', - 'tril','vander','histogram2d','mask_indices', - 'tril_indices','tril_indices_from','triu_indices','triu_indices_from', +__all__ = ['diag', 'diagflat', 'eye', 'fliplr', 'flipud', 'rot90', 'tri', 'triu', + 'tril', 'vander', 'histogram2d', 'mask_indices', + 'tril_indices', 'tril_indices_from', 'triu_indices', 'triu_indices_from', ] from numpy.core.numeric import asanyarray, equal, subtract, arange, \ @@ -113,7 +113,7 @@ def flipud(m): m = asanyarray(m) if m.ndim < 1: raise ValueError("Input must be >= 1-d.") - return m[::-1,...] + return m[::-1, ...] def rot90(m, k=1): """ @@ -160,12 +160,12 @@ def rot90(m, k=1): if k == 0: return m elif k == 1: - return fliplr(m).swapaxes(0,1) + return fliplr(m).swapaxes(0, 1) elif k == 2: return fliplr(flipud(m)) else: # k == 3 - return fliplr(m.swapaxes(0,1)) + return fliplr(m.swapaxes(0, 1)) def eye(N, M=None, k=0, dtype=float): """ @@ -276,7 +276,7 @@ def diag(v, k=0): s = v.shape if len(s) == 1: n = s[0]+abs(k) - res = zeros((n,n), v.dtype) + res = zeros((n, n), v.dtype) if k >= 0: i = k else: @@ -334,12 +334,12 @@ def diagflat(v, k=0): v = asarray(v).ravel() s = len(v) n = s + abs(k) - res = zeros((n,n), v.dtype) + res = zeros((n, n), v.dtype) if (k >= 0): - i = arange(0,n-k) + i = arange(0, n-k) fi = i+k+i*n else: - i = arange(0,n+k) + i = arange(0, n+k) fi = i+(i-k)*n res.flat[fi] = v if not wrap: @@ -385,7 +385,7 @@ def tri(N, M=None, k=0, dtype=float): """ if M is None: M = N - m = greater_equal(subtract.outer(arange(N), arange(M)),-k) + m = greater_equal(subtract.outer(arange(N), arange(M)), -k) return m.astype(dtype) def tril(m, k=0): @@ -421,7 +421,7 @@ def tril(m, k=0): """ m = asanyarray(m) - out = multiply(tri(m.shape[0], m.shape[1], k=k, dtype=m.dtype),m) + out = multiply(tri(m.shape[0], m.shape[1], k=k, dtype=m.dtype), m) return out def triu(m, k=0): @@ -510,9 +510,9 @@ def vander(x, N=None): x = asarray(x) if N is None: N=len(x) - X = ones( (len(x),N), x.dtype) + X = ones( (len(x), N), x.dtype) for i in range(N - 1): - X[:,i] = x**(N - i - 1) + X[:, i] = x**(N - i - 1) return X @@ -650,7 +650,7 @@ def histogram2d(x, y, bins=10, range=None, normed=False, weights=None): if N != 1 and N != 2: xedges = yedges = asarray(bins, float) bins = [xedges, yedges] - hist, edges = histogramdd([x,y], bins, range, normed, weights) + hist, edges = histogramdd([x, y], bins, range, normed, weights) return hist, edges[0], edges[1] @@ -719,7 +719,7 @@ def mask_indices(n, mask_func, k=0): array([1, 2, 5]) """ - m = ones((n,n), int) + m = ones((n, n), int) a = mask_func(m, k) return where(a != 0) @@ -929,4 +929,4 @@ def triu_indices_from(arr, k=0): """ if not (arr.ndim == 2 and arr.shape[0] == arr.shape[1]): raise ValueError("input array must be 2-d and square") - return triu_indices(arr.shape[0],k) + return triu_indices(arr.shape[0], k) diff --git a/numpy/lib/type_check.py b/numpy/lib/type_check.py index d52ad095d..1ed5bf32a 100644 --- a/numpy/lib/type_check.py +++ b/numpy/lib/type_check.py @@ -3,9 +3,9 @@ """ from __future__ import division, absolute_import, print_function -__all__ = ['iscomplexobj','isrealobj','imag','iscomplex', - 'isreal','nan_to_num','real','real_if_close', - 'typename','asfarray','mintypecode','asscalar', +__all__ = ['iscomplexobj', 'isrealobj', 'imag', 'iscomplex', + 'isreal', 'nan_to_num', 'real', 'real_if_close', + 'typename', 'asfarray', 'mintypecode', 'asscalar', 'common_type'] import numpy.core.numeric as _nx @@ -68,7 +68,7 @@ def mintypecode(typechars,typeset='GDFgdf',default='d'): l = [] for t in intersection: i = _typecodes_by_elsize.index(t) - l.append((i,t)) + l.append((i, t)) l.sort() return l[0][1] @@ -102,7 +102,7 @@ def asfarray(a, dtype=_nx.float_): dtype = _nx.obj2sctype(dtype) if not issubclass(dtype, _nx.inexact): dtype = _nx.float_ - return asarray(a,dtype=dtype) + return asarray(a, dtype=dtype) def real(val): """ diff --git a/numpy/lib/user_array.py b/numpy/lib/user_array.py index cc9612427..f62f6db59 100644 --- a/numpy/lib/user_array.py +++ b/numpy/lib/user_array.py @@ -39,9 +39,9 @@ class container(object): def __setitem__(self, index, value): - self.array[index] = asarray(value,self.dtype) + self.array[index] = asarray(value, self.dtype) def __setslice__(self, i, j, value): - self.array[i:j] = asarray(value,self.dtype) + self.array[i:j] = asarray(value, self.dtype) def __abs__(self): return self._rc(absolute(self.array)) @@ -65,16 +65,16 @@ class container(object): return self def __mul__(self, other): - return self._rc(multiply(self.array,asarray(other))) + return self._rc(multiply(self.array, asarray(other))) __rmul__ = __mul__ def __imul__(self, other): multiply(self.array, other, self.array) return self def __div__(self, other): - return self._rc(divide(self.array,asarray(other))) + return self._rc(divide(self.array, asarray(other))) def __rdiv__(self, other): - return self._rc(divide(asarray(other),self.array)) + return self._rc(divide(asarray(other), self.array)) def __idiv__(self, other): divide(self.array, other, self.array) return self @@ -88,32 +88,32 @@ class container(object): return self def __divmod__(self, other): - return (self._rc(divide(self.array,other)), + return (self._rc(divide(self.array, other)), self._rc(remainder(self.array, other))) def __rdivmod__(self, other): return (self._rc(divide(other, self.array)), self._rc(remainder(other, self.array))) - def __pow__(self,other): - return self._rc(power(self.array,asarray(other))) - def __rpow__(self,other): - return self._rc(power(asarray(other),self.array)) - def __ipow__(self,other): + def __pow__(self, other): + return self._rc(power(self.array, asarray(other))) + def __rpow__(self, other): + return self._rc(power(asarray(other), self.array)) + def __ipow__(self, other): power(self.array, other, self.array) return self - def __lshift__(self,other): + def __lshift__(self, other): return self._rc(left_shift(self.array, other)) - def __rshift__(self,other): + def __rshift__(self, other): return self._rc(right_shift(self.array, other)) - def __rlshift__(self,other): + def __rlshift__(self, other): return self._rc(left_shift(other, self.array)) - def __rrshift__(self,other): + def __rrshift__(self, other): return self._rc(right_shift(other, self.array)) - def __ilshift__(self,other): + def __ilshift__(self, other): left_shift(self.array, other, self.array) return self - def __irshift__(self,other): + def __irshift__(self, other): right_shift(self.array, other, self.array) return self @@ -163,12 +163,12 @@ class container(object): def __hex__(self): return self._scalarfunc(hex) def __oct__(self): return self._scalarfunc(oct) - def __lt__(self,other): return self._rc(less(self.array,other)) - def __le__(self,other): return self._rc(less_equal(self.array,other)) - def __eq__(self,other): return self._rc(equal(self.array,other)) - def __ne__(self,other): return self._rc(not_equal(self.array,other)) - def __gt__(self,other): return self._rc(greater(self.array,other)) - def __ge__(self,other): return self._rc(greater_equal(self.array,other)) + def __lt__(self, other): return self._rc(less(self.array, other)) + def __le__(self, other): return self._rc(less_equal(self.array, other)) + def __eq__(self, other): return self._rc(equal(self.array, other)) + def __ne__(self, other): return self._rc(not_equal(self.array, other)) + def __gt__(self, other): return self._rc(greater(self.array, other)) + def __ge__(self, other): return self._rc(greater_equal(self.array, other)) def copy(self): return self._rc(self.array.copy()) @@ -185,7 +185,7 @@ class container(object): def __array_wrap__(self, *args): return self.__class__(args[0]) - def __setattr__(self,attr,value): + def __setattr__(self, attr, value): if attr == 'array': object.__setattr__(self, attr, value) return @@ -195,7 +195,7 @@ class container(object): object.__setattr__(self, attr, value) # Only called after other approaches fail. - def __getattr__(self,attr): + def __getattr__(self, attr): if (attr == 'array'): return object.__getattribute__(self, attr) return self.array.__getattribute__(attr) @@ -204,19 +204,19 @@ class container(object): # Test of class container ############################################################# if __name__ == '__main__': - temp=reshape(arange(10000),(100,100)) + temp=reshape(arange(10000), (100, 100)) ua=container(temp) # new object created begin test print(dir(ua)) - print(shape(ua),ua.shape) # I have changed Numeric.py + print(shape(ua), ua.shape) # I have changed Numeric.py - ua_small=ua[:3,:5] + ua_small=ua[:3, :5] print(ua_small) - ua_small[0,0]=10 # this did not change ua[0,0], which is not normal behavior - print(ua_small[0,0],ua[0,0]) + ua_small[0, 0]=10 # this did not change ua[0,0], which is not normal behavior + print(ua_small[0, 0], ua[0, 0]) print(sin(ua_small)/3.*6.+sqrt(ua_small**2)) - print(less(ua_small,103),type(less(ua_small,103))) - print(type(ua_small*reshape(arange(15),shape(ua_small)))) - print(reshape(ua_small,(5,3))) + print(less(ua_small, 103), type(less(ua_small, 103))) + print(type(ua_small*reshape(arange(15), shape(ua_small)))) + print(reshape(ua_small, (5, 3))) print(transpose(ua_small)) diff --git a/numpy/lib/utils.py b/numpy/lib/utils.py index f54946722..1b968f1fc 100644 --- a/numpy/lib/utils.py +++ b/numpy/lib/utils.py @@ -320,7 +320,7 @@ def who(vardict=None): sta = [] cache = {} for name in vardict.keys(): - if isinstance(vardict[name],ndarray): + if isinstance(vardict[name], ndarray): var = vardict[name] idv = id(var) if idv in cache.keys(): @@ -351,9 +351,9 @@ def who(vardict=None): totalbytes += int(val[2]) if len(sta) > 0: - sp1 = max(10,maxname) - sp2 = max(10,maxshape) - sp3 = max(10,maxbyte) + sp1 = max(10, maxname) + sp2 = max(10, maxshape) + sp3 = max(10, maxbyte) prval = "Name %s Shape %s Bytes %s Type" % (sp1*' ', sp2*' ', sp3*' ') print(prval + "\n" + "="*(len(prval)+5) + "\n") @@ -409,7 +409,7 @@ def _makenamedict(module='numpy'): break thisdict = totraverse.pop(0) for x in thisdict.keys(): - if isinstance(thisdict[x],types.ModuleType): + if isinstance(thisdict[x], types.ModuleType): modname = thisdict[x].__name__ if modname not in dictlist: moddict = thisdict[x].__dict__ @@ -470,7 +470,7 @@ def info(object=None,maxwidth=76,output=sys.stdout,toplevel='numpy'): # Local import to speed up numpy's import time. import pydoc, inspect - if hasattr(object,'_ppimport_importer') or \ + if hasattr(object, '_ppimport_importer') or \ hasattr(object, '_ppimport_module'): object = object._ppimport_module elif hasattr(object, '_ppimport_attr'): @@ -537,7 +537,7 @@ def info(object=None,maxwidth=76,output=sys.stdout,toplevel='numpy'): print(" " + argstr + "\n", file=output) doc1 = inspect.getdoc(object) if doc1 is None: - if hasattr(object,'__init__'): + if hasattr(object, '__init__'): print(inspect.getdoc(object.__init__), file=output) else: print(inspect.getdoc(object), file=output) @@ -565,7 +565,7 @@ def info(object=None,maxwidth=76,output=sys.stdout,toplevel='numpy'): else: arguments = "()" - if hasattr(object,'name'): + if hasattr(object, 'name'): name = "%s" % object.name else: name = "<name>" @@ -972,7 +972,7 @@ class SafeEval(object): if sys.version_info[0] < 3: def visit(self, node, **kw): cls = node.__class__ - meth = getattr(self,'visit'+cls.__name__,self.default) + meth = getattr(self, 'visit'+cls.__name__, self.default) return meth(node, **kw) def default(self, node, **kw): @@ -987,7 +987,7 @@ class SafeEval(object): return node.value def visitDict(self, node,**kw): - return dict([(self.visit(k),self.visit(v)) for k,v in node.items]) + return dict([(self.visit(k), self.visit(v)) for k, v in node.items]) def visitTuple(self, node, **kw): return tuple([self.visit(i) for i in node.nodes]) |