NumPy Arrays – Numerical Python Arrays
Our focus today is on numPy arrays with examples, in order to provide users with a more effective learning experience. NumPy’s main object is homogeneous multidimensional arrays.
It is basically a table with all elements having the same type and indexed by a positive integer tuple.
Syntax
numpy.array(object, dtype=None, copy=True, order='K', subok=False, ndmin=0)
NumPy ndarray Object
The NumPy library is utilized to deal with arrays. When NumPy makes arrays, the array object is known as ndarray.
By calling NumPy array() function, we can make a NumPy ndarray object.
Example:1 
Example:2 
A list, tuple, or any array-like object can be provided to the array() method to generate an ndarray.
Make a NumPy array utilizing a tuple:
Example:1 
Example:2 
Array Dimensions
When we discuss numpy arrays, a dimension is the size of the array (nested arrays).
nested array (array in an array): The components of arrays are arrays.
Array 0-D
The components of an array are 0-D arrays, or scalars. In an array, a value is a 0-D array.
Make a 0-D array with the element “mrexamples”:
Example: 
Set 33 as the value of a 0-D array:
Example: 
Array 1-D
When numpy generates arrays, a 1-D array that has 0-D arrays is known as a 1-D array.
The most frequently used and fundamental arrays are listed here.
Make a 1-D array that includes 1990,1995,2000,2005,2010,2015,2020,2025:
Example:1 
Example:2 
Array 2-D
A 2-D array a collection of 1-D arrays as its components, as we are talking about numpy creating arrays.
In many cases, they are utilized to display matrices or tensors of second order.
A complete separate module of NumPy is dedicated to matrix operations known as numpy.mat
You will need to generate a 2-D array that includes two arrays with the elements “Washington”,”London”,”Berlin” and “Paris”,”Islamabad”,”Rome”:
Example: 
Make a 2-D array with three arrays with the elements 1, 2, 3, 4, 5 and 2, 4, 6, 8, 10 and 1, 3, 5, 7, 9:
Example: 
Array 3-D
Arrays with components that are 2-D arrays (matrices) are known as 3-D arrays.
Third order tensors are most commonly displayed by these.
Make a 3-D array from two 2-D arrays, each having two arrays with the data “Washington”,”London”,”Berlin” and “Paris”,”Islamabad”,”Rome”:
Example: 
Build a 3-D array using two 2-D arrays, two arrays including three arrays with the data 1, 2, 3, 4, 5 and 2, 4, 6, 8, 10 and 1, 3, 5, 7, 9:
Example: 
Number of Dimensions
The ndim attribute of NumPy Arrays provides an integer indicating the number of dimensions the array has.
Find out the number of dimensions the array contains:
Example:1 
Example:2 
Higher Dimensional Arrays
It is important to note that when dealing with numpy arrays, every number of dimensions is possible.
By passing the ndmin argument, the user can set the number of dimensions for the array.
Check that an array has 4 dimensions by making an array with 4 dimensions:
Example:1 
Example:2 
There are eight components in the innermost dimension (4th dim) of this array, One component of the 3rd dimension is the matrix with the vector, There is one component in the 2nd dimension that is a 3D array,
And one component in the 1st dimension that is a 4D array.
NumPy Array Indexing
Numpy array indexing equates to referencing an array element when we discuss array indexing.
By referring to an array element’s index number, you can locate it.
Access Array Element
NumPy arrays contain indexes beginning with 0, so the first item has index 0, and the second has index 1, etc.
From the below array, retrieve the first item:
Example:1 
Example:2 
From the below array, retrieve the third item:
Example:1 
Example:2 
In the below array, find the fourth and fifth items and add both together:
Example:1 
Example:2 
Access 2-D Arrays
Numpy array indexing allows us to retrieve data from 2-D arrays by utilizing comma-separated numbers that indicate the dimension and the index.
The 3rd item on the 1st dimension can be located as follows:
Example:1 
Example:2 
The 5th item on the 2nd dimension can be found as follows:
Example:1 
Example:2 
Access 3-D Arrays
Numpy array indexing allows us to locate items in 3-D arrays through comma-separated integers defining the dimensions and index.
The third item of the second array of the first array can be located as follows:
Example: 
Explanation of above example:
mrx_arr[0, 1, 2] displays the digit 10.
Here’s why:
This number indicates the first dimension, which has two arrays:
[[0, 2, 4], [6, 8, 10]]
and:
[[1, 3, 5], [7, 9, 11]]
We now have the first array since we chose 0:
[[0, 2, 4], [6, 8, 10]]
The second number indicates the second dimension, which is also built up of two arrays:
[0, 2, 4]
and:
[6, 8, 10]
Having selected 1, we now have the second array:
[6, 8, 10]
There are three items in the third dimension, which is indicated by the third number:
6
8
10
As an outcome of selecting 2, we end up with the third item:
10
Another Example: 
Explanation:
mrx_arr[0, 1, 2] displays the word Philadelphia.
Here’s why:
This number indicates the first dimension, which has two arrays:
[[“New York City”, “Los Angeles”, “Chicago”], [“Houston”, “Phoenix “, “Philadelphia”]]
and:
[[“San Antonio”, “San Antonio”, “Dallas “], [“San Jose”, “Austin, TX”, “Jacksonville, FLA”]]
We now have the first array since we chose 0:
[[“New York City”, “Los Angeles”, “Chicago”], [“Houston”, “Phoenix “, “Philadelphia”]]
The second number indicates the second dimension, which is also built up of two arrays:
[“New York City”, “Los Angeles”, “Chicago”]
and:
[“Houston”, “Phoenix “, “Philadelphia”]
Having selected 1, we now have the second array:
[“Houston”, “Phoenix “, “Philadelphia”]
There are three items in the third dimension, which is indicated by the third number:
“Houston”
“Phoenix “
“Philadelphia”
As an outcome of selecting 2, we end up with the third item:
“Philadelphia”
Negative Indexing
To retrieve an array from the tail, utilize negative indexing.
From the second dimension, display the second last item:
Example:1 
Example:2 
The next chapter will provide you with more information on numPy data types.