NumPy
NumPy is a library for Python that adds support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.
In this section, we will go over the following topics:
- Generating NumPy arrays
- Operating NumPy arrays
We will start with how to generate NumPy arrays.
Generating NumPy arrays
In this section, we will demonstrate various ways to create NumPy arrays. Arrays might be one-dimensional or two-dimensional.
Let’s convert a list into a one-dimensional array by using the following code (the first line imports the NumPy library and and gives it the alias of np
):
import numpy as np my_list = [1,2,3] my_list [1, 2, 3] import numpy as np my_list = [1,2,3] arr = np.array(my_list) arr array([1, 2, 3])
Now, let’s make our list a little complicated with the following code:
import numpy as np my_mat =[[10,20,30],[40,50,60],[70,80,90]] np.array(my_mat...