In [1]:
import random
N=10*1000*1000
A=[0 for i in xrange(N)]
B=[1000.*random.random() for i in xrange(N)]
C=[1000.*random.random() for i in xrange(N)]
d=0.2

In [2]:
%%timeit
for i in xrange(N):
A[i] = B[i] + d * C[i]

1 loops, best of 3: 2.45 s per loop

In [4]:
%%timeit?

In [6]:
import numpy as np
a = np.array(A)
b=np.array(B)
c=np.array(C)

In [7]:
%%timeit
a = b + d*c

10 loops, best of 3: 62.9 ms per loop

In [8]:
x = np.arange(-2.,2.5,.5)

In [9]:
print x

[-2.  -1.5 -1.  -0.5  0.   0.5  1.   1.5  2. ]

In [10]:
print np.ceil(x)

[-2. -1. -1. -0.  0.  1.  1.  2.  2.]

In [11]:
print np.exp(x)

[ 0.13533528  0.22313016  0.36787944  0.60653066  1.          1.64872127
2.71828183  4.48168907  7.3890561 ]

In [12]:
print np.subtract(x, np.ceil(x))

[ 0.  -0.5  0.  -0.5  0.  -0.5  0.  -0.5  0. ]

In [15]:
print x - np.ceil(x) < 0

[False  True False  True False  True False  True False]

In [21]:
print np.cumsum(x)

[-2.  -3.5 -4.5 -5.  -5.  -4.5 -3.5 -2.   0. ]

In [22]:
print x

[-2.  -1.5 -1.  -0.5  0.   0.5  1.   1.5  2. ]

In [20]:
print np.std(x)

1.29099444874

In [24]:
x=np.random.rand(1200 * 50 * 24 *36).reshape((1200, 50, 24,36))

In [27]:
y=np.average(x, 0)

In [30]:
size(x)/size(y)

Out[30]:
1200
In [33]:
y[49,23,35]

Out[33]:
0.50617695896530213
In [36]:
import Nio

In [48]:
cesm_file=Nio.open_file("/glade/p/cesm0005/csm/b.e11.BLMTRC5CN.f19_g16.008/atm/hist/b.e11.BLMTRC5CN.f19_g16.008.cam.h1.1662-01-01-00000.nc")

In [53]:
t=cesm_file.variables["T850"][:]

In [55]:
t.shape

Out[55]:
(365, 96, 144)
In [56]:
t_avg=np.average(t, 0)

In [57]:
t_avg.shape

Out[57]:
(96, 144)
In [58]:
from pylab import *

In [60]:
import matplotlib.pyplot as plt

In [61]:
plt.contourf(t_avg)

Out[61]:
<matplotlib.contour.QuadContourSet instance at 0x2eb0e4588248>