summaryrefslogtreecommitdiff
path: root/numpy/oldnumeric/random_array.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/oldnumeric/random_array.py')
-rw-r--r--numpy/oldnumeric/random_array.py34
1 files changed, 17 insertions, 17 deletions
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()