Scientific Python 101: Numpy
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.
- Create a one dimensional array containing 100 dice roll results (uniformly distributed integers 1..6). Print all the results that are less than 5.
- 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 np.dot for the multiplication.
- 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.