Numpy package is one the most widely used library in the Python environment. It enables straightforwardly vectorising the operations. In the world of Deep Learning and Neural Networks, this is a desirable quality.
Numpy's main object is a multidimensional array storing elements of the same type, usually numbers. The arrays (umpy.array) created using the library differ from the ones in Python standard library (array.array). Let us first run the Python command line and import the package.
import numpy as np
There are several ways on how to create the arrays. The easiest is to provide the set of value, by passing a regular Python list or tuple using the array function.
np.array([2, 4, 15])
np.array([[1, 2], [3, 4], [5, 6]])
The transformations change sequences of sequences into two-dimensional arrays, sequences of sequences of sequences into three-dimensional arrays, and so on. Notice that the following line will return with the error:
np.array(2, 4, 15)
To find out about the shape of the array use the following:
a = np.array([[1, 2], [3, 4], [5, 6]])
To change it, use the reshape function:
You may find the functions zeros and ones useful to create arrays containing only 0s or 1s:
For the randomly generated numbers apply: