From 8936ecc8c46b92f4dbc749e294eb5ab88ab0d857 Mon Sep 17 00:00:00 2001 From: Alan McIntyre Date: Fri, 25 Jul 2008 16:09:26 +0000 Subject: Standardize NumPy import as "import numpy as np". --- numpy/oldnumeric/random_array.py | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'numpy/oldnumeric/random_array.py') diff --git a/numpy/oldnumeric/random_array.py b/numpy/oldnumeric/random_array.py index 73564811d..e84aedf1e 100644 --- a/numpy/oldnumeric/random_array.py +++ b/numpy/oldnumeric/random_array.py @@ -10,7 +10,7 @@ __all__ = ['ArgumentError','F','beta','binomial','chi_square', 'exponential', ArgumentError = ValueError import numpy.random.mtrand as mt -import numpy as Numeric +import numpy as np def seed(x=0, y=0): if (x == 0 or y == 0): @@ -48,8 +48,8 @@ def randint(minimum, maximum=None, shape=[]): if not isinstance(maximum, int): raise ArgumentError, "randint requires second argument integer" a = ((maximum-minimum)* random(shape)) - if isinstance(a, Numeric.ndarray): - return minimum + a.astype(Numeric.int) + if isinstance(a, np.ndarray): + return minimum + a.astype(np.int) else: return minimum + int(a) @@ -164,7 +164,7 @@ def multinomial(trials, probs, shape=[]): trials is the number of trials in each multinomial distribution. probs is a one dimensional array. There are len(prob)+1 events. prob[i] is the probability of the i-th event, 0<=i= 0.6: + 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]) @@ -229,26 +229,26 @@ 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(Numeric.array([10,20]), Numeric.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(Numeric.array([10,20]), Numeric.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(Numeric.array([-100,0,100]), Numeric.array([[3,2,1],[2,2,1],[1,1,1]]), 10000) - x_mean = Numeric.sum(x,axis=0)/10000. + 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 Numeric.dot(Numeric.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) mean_var_test(x, "gamma(.01,2.) random numbers", 2*100, 2*100*100) x = chi_square(11., 10000) - mean_var_test(x, "chi squared random numbers with 11 degrees of freedom", 11, 22, 2*Numeric.sqrt(2./11.)) + mean_var_test(x, "chi squared random numbers with 11 degrees of freedom", 11, 22, 2*np.sqrt(2./11.)) x = F(5., 10., 10000) mean_var_test(x, "F random numbers with 5 and 10 degrees of freedom", 1.25, 1.35) x = poisson(50., 10000) @@ -260,7 +260,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 = ", Numeric.sum(x,axis=0)/8. + print "Mean = ", np.sum(x,axis=0)/8. if __name__ == '__main__': test() -- cgit v1.2.1