Scientific Python 101: Numpy

team work.JPG

In this series we'll introduce a few scientific python libraries that you will be using all the time when handling data and doing machine learning.  First up: numpy.  This is a library that allows you to create and manipulate arrays, perform linear algebra and generate random numbers, amoungst other things.  For a full reference check out the documentation here.


  1.  Create a one dimensional array containing 100 dice roll results (uniformly distributed integers 1..6).  Print all the results that are less than 5.
  2.   Define a three dimensional diagonal matrix that will multiply a vector with three components to give the vector with its first two components unchanged but its third component multiplied by 10.  (So (1,1,1) -> (1,1,10))  Check it works using for the multiplication.
  3.   Make a one dimensional array of 16 Poisson random numbers, lambda = 3.  Reshape the array so that it has dimensions (4,4).  Set all of the elements of the array that are equal to zero to be equal to 0.01.
Abbey Waldronpython, numpy