In this article, we will learn about the advantages of a Numpy array with a Nested List in Python. The Numpy array definitely has advantages over a Nested. Let’s see the reasons − The array in Numpy executes faster than a Nested List. A Nested...
In this article, we will learn about the advantages of a Numpy array with a Nested List in Python. The Numpy array definitely has advantages over a Nested. Let’s see the reasons −
NumPy is an N-dimensional array type called ndarray. It describes the collection of items of the same type. Items in the collection can be accessed using a zero-based index.
Every item in an ndarray takes the same size of block in the memory. Each element in ndarray is an object of data-type object
The basic Numpy Array is created using an array() function in NumPy:
Array = [ 5 10 15 20 25]
In this example, we will create a matrix using the numpy library −
Array = [[ 5 10 15] [20 25 30]]
A nested list as the name suggests is a list of lists. They can be used to create a matrix as well.
With Nested Lists, you can easily create a matrix in Python. In a Nested List.
Let us see an example −
Number of rows = 3 Number of columns = 3 Matrix = [5, 10, 15] [50, 100, 150] [100, 150, 200]
The above example displays nested list −