The NumPy module


In [ ]:
import numpy as np

In [ ]:
a = np.array([1,4,9,16,25,36])

In [ ]:
a

In [ ]:
amulti = np.array([[1,4,9],[16,25,36]])

In [ ]:
amulti

In [ ]:
a[0]

In [ ]:
a[5]

In [ ]:
amulti[1][1]

In [ ]:
amulti.shape

In [ ]:
amulti.size

In [ ]:
a.shape

In [ ]:
a.size

In [ ]:
a = np.array([1,4,9,16,25,36],dtype=float)

In [ ]:
a

In [ ]:
b = np.arange(6)

In [ ]:
b

In [ ]:
np.ones(6)

In [ ]:
c = np.ones_like(a)

In [ ]:
c

In [ ]:
mylist = [5,4,3,2,1,-1]

d = np.array(mylist, dtype=float)

d

In [ ]:
e = a + b

In [ ]:
e

In [ ]:
a - b

In [ ]:
b / a

In [ ]:
b * a

In [ ]:
a**0.5

In [ ]:
np.sqrt(a)

In [ ]:
a.sum()

In [ ]:
a.min()

In [ ]:
a.max()

In [ ]:
np.log10(a)

In [ ]:
d = np.array([3,2,9,-10,17,3])

In [ ]:
d

In [ ]:
e = np.sort(d)

In [ ]:
e

what have we learned?

  • Numpy - important package for scientific computing in python
  • Numpy arrays - fundamental data type
  • Lots of ways to create Numpy arrays
  • Can do operations on entire arrays of numbers
  • Many built-in methods to work with numpy arrays

In [ ]: