In which we cover Numpy

Numpy is a library that was based on Scipy


In [1]:
a = [1,2, 3,4,5]

In [2]:
b = []
for i in a:
    b.append(i * 2)
    
print b


[2, 4, 6, 8, 10]

In [3]:
a * 2


Out[3]:
[1, 2, 3, 4, 5, 1, 2, 3, 4, 5]

In [4]:
b = range(5)
print b


[0, 1, 2, 3, 4]

In [5]:
# This code will fail. Uncomment to try it
#a *b

In [6]:
import numpy as np

a2 = np.array([1,2,3,4,5])
print a2


[1 2 3 4 5]

In [7]:
a2 * 2


Out[7]:
array([ 2,  4,  6,  8, 10])

In [8]:
b2 = np.arange(5)
print b2


[0 1 2 3 4]

In [9]:
a2 * b2


Out[9]:
array([ 0,  2,  6, 12, 20])

In [10]:
a3 = np.array([2, 56, 1, 9, 0])
np.sort(a3)


Out[10]:
array([ 0,  1,  2,  9, 56])

In [11]:
np.mean(a2)


Out[11]:
3.0

In [12]:
np.average(a2)


Out[12]:
3.0

In [12]: