summaryrefslogtreecommitdiff
path: root/numpy/oldnumeric
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-08-18 11:51:25 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-08-18 11:51:25 -0600
commitfbd6510d58a47ea0d166c48a82793f05425406e4 (patch)
tree330ce703eb02d20f96099c3fe0fc36ae33d4905b /numpy/oldnumeric
parent8ddb0ce0acafe75d78df528b4d2540dfbf4b364d (diff)
downloadnumpy-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/oldnumeric')
-rw-r--r--numpy/oldnumeric/alter_code1.py32
-rw-r--r--numpy/oldnumeric/alter_code2.py18
-rw-r--r--numpy/oldnumeric/arrayfns.py10
-rw-r--r--numpy/oldnumeric/fix_default_axis.py10
-rw-r--r--numpy/oldnumeric/functions.py6
-rw-r--r--numpy/oldnumeric/linear_algebra.py6
-rw-r--r--numpy/oldnumeric/ma.py26
-rw-r--r--numpy/oldnumeric/matrix.py2
-rw-r--r--numpy/oldnumeric/mlab.py10
-rw-r--r--numpy/oldnumeric/random_array.py34
-rw-r--r--numpy/oldnumeric/rng.py10
-rw-r--r--numpy/oldnumeric/rng_stats.py6
-rw-r--r--numpy/oldnumeric/setup.py2
-rw-r--r--numpy/oldnumeric/tests/test_oldnumeric.py90
-rw-r--r--numpy/oldnumeric/tests/test_regression.py2
15 files changed, 132 insertions, 132 deletions
diff --git a/numpy/oldnumeric/alter_code1.py b/numpy/oldnumeric/alter_code1.py
index 34a59a7ca..2d4e17106 100644
--- a/numpy/oldnumeric/alter_code1.py
+++ b/numpy/oldnumeric/alter_code1.py
@@ -67,7 +67,7 @@ for char in _chars.keys():
def fixtypechars(fstr):
for name in _func2 + _func4 + _meth1:
- fstr = func_re[name].sub('\\1B\\2',fstr)
+ fstr = func_re[name].sub('\\1B\\2', fstr)
for char in _chars.keys():
fstr = meth_re[char].sub('\\1%s\\2'%_chars[char], fstr)
return fstr
@@ -83,13 +83,13 @@ def changeimports(fstr, name, newname):
fstr = re.sub(r'(import\s+[^,\n\r]+,\s*)(%s)' % name,
"\\1%s as %s" % (newname, name), fstr)
fstr = fstr.replace(importasstr, 'import %s as ' % newname)
- fstr = fstr.replace(importstr, 'import %s as %s' % (newname,name))
+ fstr = fstr.replace(importstr, 'import %s as %s' % (newname, name))
ind = 0
Nlen = len(fromstr)
Nlen2 = len("from %s import " % newname)
while True:
- found = fstr.find(fromstr,ind)
+ found = fstr.find(fromstr, ind)
if (found < 0):
break
ind = found + Nlen
@@ -111,15 +111,15 @@ def fixistesting(astr):
return astr
def replaceattr(astr):
- astr = astr.replace(".typecode()",".dtype.char")
- astr = astr.replace(".iscontiguous()",".flags.contiguous")
- astr = astr.replace(".byteswapped()",".byteswap()")
+ astr = astr.replace(".typecode()", ".dtype.char")
+ astr = astr.replace(".iscontiguous()", ".flags.contiguous")
+ astr = astr.replace(".byteswapped()", ".byteswap()")
astr = astr.replace(".toscalar()", ".item()")
- astr = astr.replace(".itemsize()",".itemsize")
+ astr = astr.replace(".itemsize()", ".itemsize")
# preserve uses of flat that should be o.k.
- tmpstr = flatindex_re.sub(r"@@@@\2",astr)
+ tmpstr = flatindex_re.sub(r"@@@@\2", astr)
# replace other uses of flat
- tmpstr = tmpstr.replace(".flat",".ravel()")
+ tmpstr = tmpstr.replace(".flat", ".ravel()")
# put back .flat where it was valid
astr = tmpstr.replace("@@@@", ".flat")
return astr
@@ -128,7 +128,7 @@ svspc2 = re.compile(r'([^,(\s]+[.]spacesaver[(][)])')
svspc3 = re.compile(r'(\S+[.]savespace[(].*[)])')
#shpe = re.compile(r'(\S+\s*)[.]shape\s*=[^=]\s*(.+)')
def replaceother(astr):
- astr = svspc2.sub('True',astr)
+ astr = svspc2.sub('True', astr)
astr = svspc3.sub(r'pass ## \1', astr)
#astr = shpe.sub('\\1=\\1.reshape(\\2)', astr)
return astr
@@ -139,7 +139,7 @@ def fromstr(filestr):
filestr = fixtypechars(filestr)
filestr = fixistesting(filestr)
filestr, fromall1 = changeimports(filestr, 'Numeric', 'numpy.oldnumeric')
- filestr, fromall1 = changeimports(filestr, 'multiarray','numpy.oldnumeric')
+ filestr, fromall1 = changeimports(filestr, 'multiarray', 'numpy.oldnumeric')
filestr, fromall1 = changeimports(filestr, 'umath', 'numpy.oldnumeric')
filestr, fromall1 = changeimports(filestr, 'Precision', 'numpy.oldnumeric.precision')
filestr, fromall1 = changeimports(filestr, 'UserArray', 'numpy.oldnumeric.user_array')
@@ -199,7 +199,7 @@ def convertall(direc=os.path.curdir, orig=1):
<usesnumeric>.py.orig. A new file named <usesnumeric>.py
is then written with the updated code.
"""
- files = glob.glob(os.path.join(direc,'*.py'))
+ files = glob.glob(os.path.join(direc, '*.py'))
for afile in files:
if afile[-8:] == 'setup.py': continue # skip these
convertfile(afile, orig)
@@ -211,16 +211,16 @@ def convertsrc(direc=os.path.curdir, ext=None, orig=1):
directory with extension give by list ext (if ext is None, then all files are
replaced)."""
if ext is None:
- files = glob.glob(os.path.join(direc,'*'))
+ files = glob.glob(os.path.join(direc, '*'))
else:
files = []
for aext in ext:
- files.extend(glob.glob(os.path.join(direc,"*.%s" % aext)))
+ files.extend(glob.glob(os.path.join(direc, "*.%s" % aext)))
for afile in files:
fid = open(afile)
fstr = fid.read()
fid.close()
- fstr, n = header_re.subn(r'numpy/oldnumeric.h',fstr)
+ fstr, n = header_re.subn(r'numpy/oldnumeric.h', fstr)
if n > 0:
if orig:
base, ext = os.path.splitext(afile)
@@ -231,7 +231,7 @@ def convertsrc(direc=os.path.curdir, ext=None, orig=1):
def _func(arg, dirname, fnames):
convertall(dirname, orig=0)
- convertsrc(dirname, ext=['h','c'], orig=0)
+ convertsrc(dirname, ext=['h', 'c'], orig=0)
def converttree(direc=os.path.curdir):
"""Convert all .py files and source code files in the tree given
diff --git a/numpy/oldnumeric/alter_code2.py b/numpy/oldnumeric/alter_code2.py
index c163c9565..1ec15c855 100644
--- a/numpy/oldnumeric/alter_code2.py
+++ b/numpy/oldnumeric/alter_code2.py
@@ -35,11 +35,11 @@ import glob
# To convert typecharacters we need to
# Not very safe. Disabled for now..
def replacetypechars(astr):
- astr = astr.replace("'s'","'h'")
- astr = astr.replace("'b'","'B'")
- astr = astr.replace("'1'","'b'")
- astr = astr.replace("'w'","'H'")
- astr = astr.replace("'u'","'I'")
+ astr = astr.replace("'s'", "'h'")
+ astr = astr.replace("'b'", "'B'")
+ astr = astr.replace("'1'", "'b'")
+ astr = astr.replace("'w'", "'H'")
+ astr = astr.replace("'u'", "'I'")
return astr
def changeimports(fstr, name, newname):
@@ -49,13 +49,13 @@ def changeimports(fstr, name, newname):
fromall=0
fstr = fstr.replace(importasstr, 'import %s as ' % newname)
- fstr = fstr.replace(importstr, 'import %s as %s' % (newname,name))
+ fstr = fstr.replace(importstr, 'import %s as %s' % (newname, name))
ind = 0
Nlen = len(fromstr)
Nlen2 = len("from %s import " % newname)
while True:
- found = fstr.find(fromstr,ind)
+ found = fstr.find(fromstr, ind)
if (found < 0):
break
ind = found + Nlen
@@ -66,7 +66,7 @@ def changeimports(fstr, name, newname):
return fstr, fromall
def replaceattr(astr):
- astr = astr.replace("matrixmultiply","dot")
+ astr = astr.replace("matrixmultiply", "dot")
return astr
def replaceother(astr):
@@ -131,7 +131,7 @@ def convertall(direc=os.path.curdir):
<usesnumeric>.py.orig. A new file named <usesnumeric>.py
is then written with the updated code.
"""
- files = glob.glob(os.path.join(direc,'*.py'))
+ files = glob.glob(os.path.join(direc, '*.py'))
for afile in files:
convertfile(afile)
diff --git a/numpy/oldnumeric/arrayfns.py b/numpy/oldnumeric/arrayfns.py
index 534ccacf7..0eb97ae9c 100644
--- a/numpy/oldnumeric/arrayfns.py
+++ b/numpy/oldnumeric/arrayfns.py
@@ -43,21 +43,21 @@ def interp(y, x, z, typ=None):
raise error("incompatible typecode")
def nz(x):
- x = asarray(x,dtype=np.ubyte)
+ x = asarray(x, dtype=np.ubyte)
if x.ndim != 1:
raise TypeError("intput must have 1 dimension.")
indxs = np.flatnonzero(x != 0)
return indxs[-1].item()+1
def reverse(x, n):
- x = asarray(x,dtype='d')
+ x = asarray(x, dtype='d')
if x.ndim != 2:
raise ValueError("input must be 2-d")
y = np.empty_like(x)
if n == 0:
y[...] = x[::-1,:]
elif n == 1:
- y[...] = x[:,::-1]
+ y[...] = x[:, ::-1]
return y
def span(lo, hi, num, d2=0):
@@ -65,7 +65,7 @@ def span(lo, hi, num, d2=0):
if d2 <= 0:
return x
else:
- ret = np.empty((d2,num),x.dtype)
+ ret = np.empty((d2, num), x.dtype)
ret[...] = x
return ret
@@ -84,7 +84,7 @@ def zmin_zmax(z, ireg):
nix = np.r_[ix, x1m[i1], x1m[i1], ix[i2] ]
niy = np.r_[iy, iy[i1], y1m[i3], y1m[i2]]
# remove any negative indices
- zres = z[nix,niy]
+ zres = z[nix, niy]
return zres.min().item(), zres.max().item()
diff --git a/numpy/oldnumeric/fix_default_axis.py b/numpy/oldnumeric/fix_default_axis.py
index 5f6128724..d4235a94c 100644
--- a/numpy/oldnumeric/fix_default_axis.py
+++ b/numpy/oldnumeric/fix_default_axis.py
@@ -82,9 +82,9 @@ def _add_axis(fstr, name, repl):
and fstr[start-8:start-1] != 'numerix' \
and fstr[start-8:start-1] != 'Numeric':
continue
- if fstr[start-1] in ['\t',' ']:
+ if fstr[start-1] in ['\t', ' ']:
k = start-2
- while fstr[k] in ['\t',' ']:
+ while fstr[k] in ['\t', ' ']:
k -= 1
if fstr[k-2:k+1] == 'def' or \
fstr[k-4:k+1] == 'class':
@@ -200,8 +200,8 @@ def _import_change(fstr, names):
ptr += 1
substr = fstr[ind:ptr]
found = 0
- substr = substr.replace('\n',' ')
- substr = substr.replace('\\','')
+ substr = substr.replace('\n', ' ')
+ substr = substr.replace('\\', '')
importnames = [x.strip() for x in substr.split(',')]
# determine if any of names are in importnames
addnames = []
@@ -277,7 +277,7 @@ def convertall(direc=os.path.curdir, import_change=False):
<usesnumeric>.py.orig. A new file named <usesnumeric>.py
is then written with the updated code.
"""
- files = glob.glob(os.path.join(direc,'*.py'))
+ files = glob.glob(os.path.join(direc, '*.py'))
for afile in files:
convertfile(afile, import_change)
diff --git a/numpy/oldnumeric/functions.py b/numpy/oldnumeric/functions.py
index c5941fb67..156a09a43 100644
--- a/numpy/oldnumeric/functions.py
+++ b/numpy/oldnumeric/functions.py
@@ -12,7 +12,7 @@ __all__ = ['take', 'repeat', 'sum', 'product', 'sometrue', 'alltrue',
'cumsum', 'cumproduct', 'compress', 'fromfunction',
'ones', 'empty', 'identity', 'zeros', 'array', 'asarray',
'nonzero', 'reshape', 'arange', 'fromstring', 'ravel', 'trace',
- 'indices', 'where','sarray','cross_product', 'argmax', 'argmin',
+ 'indices', 'where', 'sarray', 'cross_product', 'argmax', 'argmin',
'average']
def take(a, indicies, axis=0):
@@ -55,7 +55,7 @@ def ones(shape, typecode='l', savespace=0, dtype=None):
"""ones(shape, dtype=int) returns an array of the given
dimensions which is initialized to all ones.
"""
- dtype = convtypecode(typecode,dtype)
+ dtype = convtypecode(typecode, dtype)
a = mu.empty(shape, dtype)
a.fill(1)
return a
@@ -64,7 +64,7 @@ def zeros(shape, typecode='l', savespace=0, dtype=None):
"""zeros(shape, dtype=int) returns an array of the given
dimensions which is initialized to all zeros
"""
- dtype = convtypecode(typecode,dtype)
+ dtype = convtypecode(typecode, dtype)
return mu.zeros(shape, dtype)
def identity(n,typecode='l', dtype=None):
diff --git a/numpy/oldnumeric/linear_algebra.py b/numpy/oldnumeric/linear_algebra.py
index f9938b503..8208637b8 100644
--- a/numpy/oldnumeric/linear_algebra.py
+++ b/numpy/oldnumeric/linear_algebra.py
@@ -24,7 +24,7 @@ import numpy.linalg as linalg
LinAlgError = linalg.LinAlgError
def solve_linear_equations(a, b):
- return linalg.solve(a,b)
+ return linalg.solve(a, b)
# Matrix inversion
@@ -42,7 +42,7 @@ def eigenvalues(a):
return linalg.eigvals(a)
def Heigenvalues(a, UPLO='L'):
- return linalg.eigvalsh(a,UPLO)
+ return linalg.eigvalsh(a, UPLO)
# Eigenvectors
@@ -79,7 +79,7 @@ the number of rows, then residuals will be returned as an empty array
otherwise resids = sum((b-dot(A,x)**2).
Singular values less than s[0]*rcond are treated as zero.
"""
- return linalg.lstsq(a,b,rcond)
+ return linalg.lstsq(a, b, rcond)
def singular_value_decomposition(A, full_matrices=0):
return linalg.svd(A, full_matrices)
diff --git a/numpy/oldnumeric/ma.py b/numpy/oldnumeric/ma.py
index fbc0aca27..d41c68edc 100644
--- a/numpy/oldnumeric/ma.py
+++ b/numpy/oldnumeric/ma.py
@@ -1157,22 +1157,22 @@ array(data = %(data)s,
return self
def __eq__(self, other):
- return equal(self,other)
+ return equal(self, other)
def __ne__(self, other):
- return not_equal(self,other)
+ return not_equal(self, other)
def __lt__(self, other):
- return less(self,other)
+ return less(self, other)
def __le__(self, other):
- return less_equal(self,other)
+ return less_equal(self, other)
def __gt__(self, other):
- return greater(self,other)
+ return greater(self, other)
def __ge__(self, other):
- return greater_equal(self,other)
+ return greater_equal(self, other)
def astype (self, tc):
"return self as array of given type."
@@ -1772,7 +1772,7 @@ def masked_where(condition, x, copy=1):
"""Return x as an array masked where condition is true.
Also masked where x or condition masked.
"""
- cm = filled(condition,1)
+ cm = filled(condition, 1)
m = mask_or(getmask(x), cm)
return array(filled(x), copy=copy, mask=m)
@@ -2179,7 +2179,7 @@ def _clip(self,a_min,a_max,out=None):
return MaskedArray(data = self.data.clip(asarray(a_min).data,
asarray(a_max).data),
mask = mask_or(self.mask,
- mask_or(getmask(a_min),getmask(a_max))))
+ mask_or(getmask(a_min), getmask(a_max))))
array.clip = _m(_clip)
def _compress(self, cond, axis=None, out=None):
@@ -2237,7 +2237,7 @@ array.nonzero = _m(nonzero)
array.prod = _m(product)
def _ptp(a,axis=None,out=None):
- return a.max(axis,out)-a.min(axis)
+ return a.max(axis, out)-a.min(axis)
array.ptp = _m(_ptp)
array.repeat = _m(new_repeat)
array.resize = _m(resize)
@@ -2257,7 +2257,7 @@ array.squeeze = _m(_squeeze)
array.strides = property(_m(not_implemented))
array.sum = _m(sum)
-def _swapaxes(self,axis1,axis2):
+def _swapaxes(self, axis1, axis2):
return MaskedArray(data = self.data.swapaxes(axis1, axis2),
mask = self.mask.swapaxes(axis1, axis2))
array.swapaxes = _m(_swapaxes)
@@ -2269,13 +2269,13 @@ array.transpose = _m(transpose)
def _var(self,axis=None,dtype=None, out=None):
if axis is None:
return numeric.asarray(self.compressed()).var()
- a = self.swapaxes(axis,0)
+ a = self.swapaxes(axis, 0)
a = a - a.mean(axis=0)
a *= a
a /= a.count(axis=0)
- return a.swapaxes(0,axis).sum(axis)
+ return a.swapaxes(0, axis).sum(axis)
def _std(self,axis=None, dtype=None, out=None):
- return (self.var(axis,dtype))**0.5
+ return (self.var(axis, dtype))**0.5
array.var = _m(_var)
array.std = _m(_std)
diff --git a/numpy/oldnumeric/matrix.py b/numpy/oldnumeric/matrix.py
index 25dfe6302..35c795e9d 100644
--- a/numpy/oldnumeric/matrix.py
+++ b/numpy/oldnumeric/matrix.py
@@ -28,7 +28,7 @@ _todelete = ''.join(_todelete)
def _eval(astr):
- return eval(astr.translate(_table,_todelete))
+ return eval(astr.translate(_table, _todelete))
def _convert_from_string(data):
data.find
diff --git a/numpy/oldnumeric/mlab.py b/numpy/oldnumeric/mlab.py
index bc2844a87..2b357612c 100644
--- a/numpy/oldnumeric/mlab.py
+++ b/numpy/oldnumeric/mlab.py
@@ -29,7 +29,7 @@ def eye(N, M=None, k=0, typecode=None, dtype=None):
"""
dtype = convtypecode(typecode, dtype)
if M is None: M = N
- m = np.equal(np.subtract.outer(np.arange(N), np.arange(M)),-k)
+ m = np.equal(np.subtract.outer(np.arange(N), np.arange(M)), -k)
if m.dtype != dtype:
return m.astype(dtype)
@@ -39,7 +39,7 @@ def tri(N, M=None, k=0, typecode=None, dtype=None):
"""
dtype = convtypecode(typecode, dtype)
if M is None: M = N
- m = np.greater_equal(np.subtract.outer(np.arange(N), np.arange(M)),-k)
+ m = np.greater_equal(np.subtract.outer(np.arange(N), np.arange(M)), -k)
if m.dtype != dtype:
return m.astype(dtype)
@@ -84,8 +84,8 @@ def cov(m, y=None, rowvar=0, bias=0):
N = m.shape[0]
if (y.shape[0] != N):
raise ValueError("x and y must have the same number of observations")
- m = m - _Nmean(m,axis=0)
- y = y - _Nmean(y,axis=0)
+ m = m - _Nmean(m, axis=0)
+ y = y - _Nmean(y, axis=0)
if bias:
fact = N*1.0
else:
@@ -96,7 +96,7 @@ from numpy import sqrt, multiply
def corrcoef(x, y=None):
c = cov(x, y)
d = diag(c)
- return c/sqrt(multiply.outer(d,d))
+ return c/sqrt(multiply.outer(d, d))
from .compat import *
from .functions import *
diff --git a/numpy/oldnumeric/random_array.py b/numpy/oldnumeric/random_array.py
index ecb3d0b23..c43a49cdb 100644
--- a/numpy/oldnumeric/random_array.py
+++ b/numpy/oldnumeric/random_array.py
@@ -3,7 +3,7 @@
"""
from __future__ import division, absolute_import, print_function
-__all__ = ['ArgumentError','F','beta','binomial','chi_square', 'exponential',
+__all__ = ['ArgumentError', 'F', 'beta', 'binomial', 'chi_square', 'exponential',
'gamma', 'get_seed', 'mean_var_test', 'multinomial',
'multivariate_normal', 'negative_binomial', 'noncentral_F',
'noncentral_chi_square', 'normal', 'permutation', 'poisson',
@@ -19,7 +19,7 @@ def seed(x=0, y=0):
if (x == 0 or y == 0):
mt.seed()
else:
- mt.seed((x,y))
+ mt.seed((x, y))
def get_seed():
raise NotImplementedError(
@@ -189,14 +189,14 @@ def poisson(mean, shape=[]):
def mean_var_test(x, type, mean, var, skew=[]):
n = len(x) * 1.0
- x_mean = np.sum(x,axis=0)/n
+ x_mean = np.sum(x, axis=0)/n
x_minus_mean = x - x_mean
- x_var = np.sum(x_minus_mean*x_minus_mean,axis=0)/(n-1.0)
+ x_var = np.sum(x_minus_mean*x_minus_mean, axis=0)/(n-1.0)
print("\nAverage of ", len(x), type)
print("(should be about ", mean, "):", x_mean)
print("Variance of those random numbers (should be about ", var, "):", x_var)
if skew != []:
- x_skew = (np.sum(x_minus_mean*x_minus_mean*x_minus_mean,axis=0)/9998.)/x_var**(3./2.)
+ x_skew = (np.sum(x_minus_mean*x_minus_mean*x_minus_mean, axis=0)/9998.)/x_var**(3./2.)
print("Skewness of those random numbers (should be about ", skew, "):", x_skew)
def test():
@@ -206,13 +206,13 @@ def test():
if (obj2[1] - obj[1]).any():
raise SystemExit("Failed seed test.")
print("First random number is", random())
- print("Average of 10000 random numbers is", np.sum(random(10000),axis=0)/10000.)
- x = random([10,1000])
+ print("Average of 10000 random numbers is", np.sum(random(10000), axis=0)/10000.)
+ x = random([10, 1000])
if len(x.shape) != 2 or x.shape[0] != 10 or x.shape[1] != 1000:
raise SystemExit("random returned wrong shape")
x.shape = (10000,)
- print("Average of 100 by 100 random numbers is", np.sum(x,axis=0)/10000.)
- y = uniform(0.5,0.6, (1000,10))
+ print("Average of 100 by 100 random numbers is", np.sum(x, axis=0)/10000.)
+ y = uniform(0.5, 0.6, (1000, 10))
if len(y.shape) !=2 or y.shape[0] != 1000 or y.shape[1] != 10:
raise SystemExit("uniform returned wrong shape")
y.shape = (10000,)
@@ -221,7 +221,7 @@ def test():
print("randint(1, 10, shape=[50])")
print(randint(1, 10, shape=[50]))
print("permutation(10)", permutation(10))
- print("randint(3,9)", randint(3,9))
+ print("randint(3,9)", randint(3, 9))
print("random_integers(10, shape=[20])")
print(random_integers(10, shape=[20]))
s = 3.0
@@ -232,20 +232,20 @@ def test():
mean_var_test(x, "normally distributed numbers with mean 2 and variance %f"%(s**2,), 2, s**2, 0)
x = exponential(3, 10000)
mean_var_test(x, "random numbers exponentially distributed with mean %f"%(s,), s, s**2, 2)
- x = multivariate_normal(np.array([10,20]), np.array(([1,2],[2,4])))
+ x = multivariate_normal(np.array([10, 20]), np.array(([1, 2], [2, 4])))
print("\nA multivariate normal", x)
if x.shape != (2,): raise SystemExit("multivariate_normal returned wrong shape")
- x = multivariate_normal(np.array([10,20]), np.array([[1,2],[2,4]]), [4,3])
+ x = multivariate_normal(np.array([10, 20]), np.array([[1, 2], [2, 4]]), [4, 3])
print("A 4x3x2 array containing multivariate normals")
print(x)
- if x.shape != (4,3,2): raise SystemExit("multivariate_normal returned wrong shape")
- x = multivariate_normal(np.array([-100,0,100]), np.array([[3,2,1],[2,2,1],[1,1,1]]), 10000)
- x_mean = np.sum(x,axis=0)/10000.
+ if x.shape != (4, 3, 2): raise SystemExit("multivariate_normal returned wrong shape")
+ x = multivariate_normal(np.array([-100, 0, 100]), np.array([[3, 2, 1], [2, 2, 1], [1, 1, 1]]), 10000)
+ x_mean = np.sum(x, axis=0)/10000.
print("Average of 10000 multivariate normals with mean [-100,0,100]")
print(x_mean)
x_minus_mean = x - x_mean
print("Estimated covariance of 10000 multivariate normals with covariance [[3,2,1],[2,2,1],[1,1,1]]")
- print(np.dot(np.transpose(x_minus_mean),x_minus_mean)/9999.)
+ print(np.dot(np.transpose(x_minus_mean), x_minus_mean)/9999.)
x = beta(5.0, 10.0, 10000)
mean_var_test(x, "beta(5.,10.) random numbers", 0.333, 0.014)
x = gamma(.01, 2., 10000)
@@ -263,7 +263,7 @@ def test():
print("\nEach row is the result of 16 multinomial trials with probabilities [0.1, 0.5, 0.1 0.3]:")
x = multinomial(16, [0.1, 0.5, 0.1], 8)
print(x)
- print("Mean = ", np.sum(x,axis=0)/8.)
+ print("Mean = ", np.sum(x, axis=0)/8.)
if __name__ == '__main__':
test()
diff --git a/numpy/oldnumeric/rng.py b/numpy/oldnumeric/rng.py
index 1ffd47b27..06120798d 100644
--- a/numpy/oldnumeric/rng.py
+++ b/numpy/oldnumeric/rng.py
@@ -6,7 +6,7 @@ It is for backwards compatibility only.
"""
from __future__ import division, absolute_import, print_function
-__all__ = ['CreateGenerator','ExponentialDistribution','LogNormalDistribution',
+__all__ = ['CreateGenerator', 'ExponentialDistribution', 'LogNormalDistribution',
'NormalDistribution', 'UniformDistribution', 'error', 'ranf',
'default_distribution', 'random_sample', 'standard_generator']
@@ -21,7 +21,7 @@ class Distribution(object):
self._meth = meth
self._args = args
- def density(self,x):
+ def density(self, x):
raise NotImplementedError
def __call__(self, x):
@@ -61,7 +61,7 @@ class LogNormalDistribution(Distribution):
self._fac = 1.0/math.sqrt(2*math.pi)/self._sn
def density(x):
- m,s = self._args
+ m, s = self._args
y = (math.log(x)-self._mn)/self._sn
return self._fac*math.exp(-0.5*y*y)/x
@@ -76,7 +76,7 @@ class NormalDistribution(Distribution):
self._fac = 1.0/math.sqrt(2*math.pi)/s
def density(x):
- m,s = self._args
+ m, s = self._args
y = (x-m)/s
return self._fac*math.exp(-0.5*y*y)
@@ -97,7 +97,7 @@ class UniformDistribution(Distribution):
else:
return self._fac
-default_distribution = UniformDistribution(0.0,1.0)
+default_distribution = UniformDistribution(0.0, 1.0)
class CreateGenerator(object):
def __init__(self, seed, dist=None):
diff --git a/numpy/oldnumeric/rng_stats.py b/numpy/oldnumeric/rng_stats.py
index ed4781e6c..dd450343d 100644
--- a/numpy/oldnumeric/rng_stats.py
+++ b/numpy/oldnumeric/rng_stats.py
@@ -10,7 +10,7 @@ def average(data):
def variance(data):
data = Numeric.array(data)
- return Numeric.add.reduce((data-average(data,axis=0))**2)/(len(data)-1)
+ return Numeric.add.reduce((data-average(data, axis=0))**2)/(len(data)-1)
def standardDeviation(data):
data = Numeric.array(data)
@@ -26,11 +26,11 @@ def histogram(data, nbins, range = None):
data = Numeric.repeat(data,
Numeric.logical_and(Numeric.less_equal(data, max),
Numeric.greater_equal(data,
- min)),axis=0)
+ min)), axis=0)
bin_width = (max-min)/nbins
data = Numeric.floor((data - min)/bin_width).astype(Numeric.Int)
histo = Numeric.add.reduce(Numeric.equal(
- Numeric.arange(nbins)[:,Numeric.NewAxis], data), -1)
+ Numeric.arange(nbins)[:, Numeric.NewAxis], data), -1)
histo[-1] = histo[-1] + Numeric.add.reduce(Numeric.equal(nbins, data))
bins = min + bin_width*(Numeric.arange(nbins)+0.5)
return Numeric.transpose(Numeric.array([bins, histo]))
diff --git a/numpy/oldnumeric/setup.py b/numpy/oldnumeric/setup.py
index 5dd8d3c5c..13c3e0d8d 100644
--- a/numpy/oldnumeric/setup.py
+++ b/numpy/oldnumeric/setup.py
@@ -2,7 +2,7 @@ from __future__ import division, print_function
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
- config = Configuration('oldnumeric',parent_package,top_path)
+ config = Configuration('oldnumeric', parent_package, top_path)
config.add_data_dir('tests')
return config
diff --git a/numpy/oldnumeric/tests/test_oldnumeric.py b/numpy/oldnumeric/tests/test_oldnumeric.py
index 5ff8e6bd3..2c1a806ac 100644
--- a/numpy/oldnumeric/tests/test_oldnumeric.py
+++ b/numpy/oldnumeric/tests/test_oldnumeric.py
@@ -11,79 +11,79 @@ from numpy.core.numeric import float32, float64, complex64, complex128, int8, \
class test_oldtypes(unittest.TestCase):
def test_oldtypes(self, level=1):
- a1 = array([0,1,0], Float)
- a2 = array([0,1,0], float)
+ a1 = array([0, 1, 0], Float)
+ a2 = array([0, 1, 0], float)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Float8)
- a2 = array([0,1,0], float)
+ a1 = array([0, 1, 0], Float8)
+ a2 = array([0, 1, 0], float)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Float16)
- a2 = array([0,1,0], float)
+ a1 = array([0, 1, 0], Float16)
+ a2 = array([0, 1, 0], float)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Float32)
- a2 = array([0,1,0], float32)
+ a1 = array([0, 1, 0], Float32)
+ a2 = array([0, 1, 0], float32)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Float64)
- a2 = array([0,1,0], float64)
+ a1 = array([0, 1, 0], Float64)
+ a2 = array([0, 1, 0], float64)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Complex)
- a2 = array([0,1,0], complex)
+ a1 = array([0, 1, 0], Complex)
+ a2 = array([0, 1, 0], complex)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Complex8)
- a2 = array([0,1,0], complex)
+ a1 = array([0, 1, 0], Complex8)
+ a2 = array([0, 1, 0], complex)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Complex16)
- a2 = array([0,1,0], complex)
+ a1 = array([0, 1, 0], Complex16)
+ a2 = array([0, 1, 0], complex)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Complex32)
- a2 = array([0,1,0], complex64)
+ a1 = array([0, 1, 0], Complex32)
+ a2 = array([0, 1, 0], complex64)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Complex64)
- a2 = array([0,1,0], complex128)
+ a1 = array([0, 1, 0], Complex64)
+ a2 = array([0, 1, 0], complex128)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Int)
- a2 = array([0,1,0], int)
+ a1 = array([0, 1, 0], Int)
+ a2 = array([0, 1, 0], int)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Int8)
- a2 = array([0,1,0], int8)
+ a1 = array([0, 1, 0], Int8)
+ a2 = array([0, 1, 0], int8)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Int16)
- a2 = array([0,1,0], int16)
+ a1 = array([0, 1, 0], Int16)
+ a2 = array([0, 1, 0], int16)
assert_array_equal(a1, a2)
- a1 = array([0,1,0], Int32)
- a2 = array([0,1,0], int32)
+ a1 = array([0, 1, 0], Int32)
+ a2 = array([0, 1, 0], int32)
assert_array_equal(a1, a2)
try:
- a1 = array([0,1,0], Int64)
- a2 = array([0,1,0], int64)
+ a1 = array([0, 1, 0], Int64)
+ a2 = array([0, 1, 0], int64)
assert_array_equal(a1, a2)
except NameError:
# Not all systems have 64-bit integers.
pass
- a1 = array([0,1,0], UnsignedInt)
- a2 = array([0,1,0], UnsignedInteger)
- a3 = array([0,1,0], uint)
+ a1 = array([0, 1, 0], UnsignedInt)
+ a2 = array([0, 1, 0], UnsignedInteger)
+ a3 = array([0, 1, 0], uint)
assert_array_equal(a1, a3)
assert_array_equal(a2, a3)
- a1 = array([0,1,0], UInt8)
- a2 = array([0,1,0], UnsignedInt8)
- a3 = array([0,1,0], uint8)
+ a1 = array([0, 1, 0], UInt8)
+ a2 = array([0, 1, 0], UnsignedInt8)
+ a3 = array([0, 1, 0], uint8)
assert_array_equal(a1, a3)
assert_array_equal(a2, a3)
- a1 = array([0,1,0], UInt16)
- a2 = array([0,1,0], UnsignedInt16)
- a3 = array([0,1,0], uint16)
+ a1 = array([0, 1, 0], UInt16)
+ a2 = array([0, 1, 0], UnsignedInt16)
+ a3 = array([0, 1, 0], uint16)
assert_array_equal(a1, a3)
assert_array_equal(a2, a3)
- a1 = array([0,1,0], UInt32)
- a2 = array([0,1,0], UnsignedInt32)
- a3 = array([0,1,0], uint32)
+ a1 = array([0, 1, 0], UInt32)
+ a2 = array([0, 1, 0], UnsignedInt32)
+ a3 = array([0, 1, 0], uint32)
assert_array_equal(a1, a3)
assert_array_equal(a2, a3)
try:
- a1 = array([0,1,0], UInt64)
- a2 = array([0,1,0], UnsignedInt64)
- a3 = array([0,1,0], uint64)
+ a1 = array([0, 1, 0], UInt64)
+ a2 = array([0, 1, 0], UnsignedInt64)
+ a3 = array([0, 1, 0], uint64)
assert_array_equal(a1, a3)
assert_array_equal(a2, a3)
except NameError:
diff --git a/numpy/oldnumeric/tests/test_regression.py b/numpy/oldnumeric/tests/test_regression.py
index 97c5126bc..272323b81 100644
--- a/numpy/oldnumeric/tests/test_regression.py
+++ b/numpy/oldnumeric/tests/test_regression.py
@@ -8,4 +8,4 @@ class TestRegression(TestCase):
def test_numeric_random(self, level=rlevel):
"""Ticket #552"""
from numpy.oldnumeric.random_array import randint
- randint(0,50,[2,3])
+ randint(0, 50, [2, 3])