summaryrefslogtreecommitdiff
path: root/numpy/oldnumeric/random_array.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-04-06 13:25:26 -0600
committerCharles Harris <charlesr.harris@gmail.com>2013-04-06 13:25:26 -0600
commitbb726ca19f434f5055c0efceefe48d89469fcbbe (patch)
tree889782afaf67fd5acb5f222969251871c0c46e5a /numpy/oldnumeric/random_array.py
parent7441fa50523f5b4a16c854bf004d675e5bd86ab8 (diff)
downloadnumpy-bb726ca19f434f5055c0efceefe48d89469fcbbe.tar.gz
2to3: Apply `print` fixer.
Add `print_function` to all `from __future__ import ...` statements and use the python3 print function syntax everywhere. Closes #3078.
Diffstat (limited to 'numpy/oldnumeric/random_array.py')
-rw-r--r--numpy/oldnumeric/random_array.py56
1 files changed, 28 insertions, 28 deletions
diff --git a/numpy/oldnumeric/random_array.py b/numpy/oldnumeric/random_array.py
index 4dcddda12..ecb3d0b23 100644
--- a/numpy/oldnumeric/random_array.py
+++ b/numpy/oldnumeric/random_array.py
@@ -1,7 +1,7 @@
"""Backward compatible module for RandomArray
"""
-from __future__ import division, absolute_import
+from __future__ import division, absolute_import, print_function
__all__ = ['ArgumentError','F','beta','binomial','chi_square', 'exponential',
'gamma', 'get_seed', 'mean_var_test', 'multinomial',
@@ -192,12 +192,12 @@ def mean_var_test(x, type, mean, var, skew=[]):
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)
- 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
+ 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.)
- print "Skewness of those random numbers (should be about ", skew, "):", x_skew
+ print("Skewness of those random numbers (should be about ", skew, "):", x_skew)
def test():
obj = mt.get_state()
@@ -205,25 +205,25 @@ def test():
obj2 = mt.get_state()
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.
+ print("First random number is", random())
+ 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.
+ 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,)
if np.minimum.reduce(y) <= 0.5 or np.maximum.reduce(y) >= 0.6:
raise SystemExit("uniform returned out of desired range")
- 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 "random_integers(10, shape=[20])"
- print random_integers(10, shape=[20])
+ 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("random_integers(10, shape=[20])")
+ print(random_integers(10, shape=[20]))
s = 3.0
x = normal(2.0, s, [10, 1000])
if len(x.shape) != 2 or x.shape[0] != 10 or x.shape[1] != 1000:
@@ -233,19 +233,19 @@ def test():
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])))
- print "\nA multivariate normal", x
+ 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])
- print "A 4x3x2 array containing multivariate normals"
- print x
+ 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.
- print "Average of 10000 multivariate normals with mean [-100,0,100]"
- print x_mean
+ 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("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.)
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)
@@ -256,14 +256,14 @@ def test():
mean_var_test(x, "F random numbers with 5 and 10 degrees of freedom", 1.25, 1.35)
x = poisson(50., 10000)
mean_var_test(x, "poisson random numbers with mean 50", 50, 50, 0.14)
- print "\nEach element is the result of 16 binomial trials with probability 0.5:"
- print binomial(16, 0.5, 16)
- print "\nEach element is the result of 16 negative binomial trials with probability 0.5:"
- print negative_binomial(16, 0.5, [16,])
- print "\nEach row is the result of 16 multinomial trials with probabilities [0.1, 0.5, 0.1 0.3]:"
+ print("\nEach element is the result of 16 binomial trials with probability 0.5:")
+ print(binomial(16, 0.5, 16))
+ print("\nEach element is the result of 16 negative binomial trials with probability 0.5:")
+ print(negative_binomial(16, 0.5, [16,]))
+ 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(x)
+ print("Mean = ", np.sum(x,axis=0)/8.)
if __name__ == '__main__':
test()