Numpy is the core library for scientific computing in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays.
Why learn Numpy?
In the Introductory Course on Machine learning, we will be using numpy to build the models introduced in Andrew Ng’s Machine Learning course and solve the excercises. Note that octave is used in that course instead. Since most of the existing machine learning frameworks today are based on python (Tensorflow, Theano, etc), I figured it would be practical to use numpy to understand these basic machine learning models. Numpy is also easy to learn and experiment with and it plays well with the Tensorflow and Theano.
Lets start
We will be working with arrays. Arrays are numpy objects of type ndarray. They contain elements of type dtype and have a particular shape.
Numpy arrays from python lists
Creating Arrays
Array Indexing
Datatypes
Arithmetics
Statistics
Broadcasting
Array Masking
Summary
Task
Function
Snippet
Convert a list to numpy array
np.array()
np.array([1,2,3,4])
Create a null vector of size 10
np.zeros()
np.zeros(10)
Create a vector with values ranging from 10 to 49
np.arange()
np.arange(10,50)
Create a 3x3 matrix with values ranging from 0 to 8
np.reshape()
np.arange(9).reshape(3,3)
Create a 3x3 identity matrix
np.eye()
np.eye(3)
Create a 3x2x2 array with random values
np.random.random()
np.random.random([3,2,2])
Create a 4x4 array (x) with random integers from 0-99