NumPy (short for “Numerical Python”) is a Python module used for numerical computing, creating arrays and matrices, and performing very fast operations on those data structures.
To use NumPy with Python, import it at the top of your file using the following line:
import numpy as np
Writing as np allows us to use np as a shorthand for NumPy, which saves us time when calling a NumPy function (less typing = fewer errors!)
NumPy Arrays
The core of NumPy is a multidimensional Array object.
Creating NumPy Arrays from list
The NumPy .array() method is used to create new NumPy Arrays.
NumPy Arrays can be created from data in CSV files or other delimited text by using the np.genfromtxt() method. The named parameter delimiter is used to determine the delimiting character between values.
In Python, we can create lists that are made up of other lists. Similarly, in NumPy we can create an array of arrays. If the arrays that make up our bigger array are all the same size, then it has a special name: a two-dimensional array.
# this is a two-dimensional NumPy array
np.array([[92, 94, 88, 91, 87],
[79, 100, 86, 93, 91],
[87, 85, 72, 90, 92]])
# this will run but it will not create
# a two-dimensional array
np.array([[29, 49, 6],
[77, 1]])