What are NumPy arrays?
In our previous article, we discussed what the NumPy Python library is and why we need to learn it for machine learning. In this article, we will discuss what NumPy arrays are.
A NumPy array is a data structure that can be used for storing single or multi-dimensional arrays and matrices. Later that data structure can be used for performing advanced mathematical operations like matrix operations, etc.
Python has a basic data structure called lists. These lists are good for performing basic mathematical operations. But, performing advanced mathematical calculations on these lists is not easy. For that purpose, we need to use a NumPy array.
How to create a NumPy array?
We can create a NumPy array from a Python list. For example,
import numpy list1 = [1, 2, 3] list2 = [[1, 2, 3], [4, 5, 6]] list3 = [[1, 2, 3]] array1 = numpy.array(list1) array2 = numpy.array(list2) array3 = numpy.array(list3) print("Array 1: ", array1) print("Type: ", type(array1)) print("Array 2: ", array2) print("Type: ", type(array2)) print("Array 3: ", array3) print("Type: ", type(array3))
0 Comments