Multidimensional array in python

Multidimensional array in python : The multidimensional array is the two dimensional array. It has the more than one row and the columns of the elements. The two dimensional array is the list of the one dimensional array. It has two dimensional array of size[x][y] seen like table, means x no of rows and y no of columns. This matrix is called as the multidimensional array.
A=np.array ([(1, 2, 3), (2, 4, 5)]
Print (a)
Output:-
[[1 2 3]
[2 45 ]]

Python NumPy Array v/s List:-

We use python numpy array instead of a list because of the reason:-

  1. Fast
  2. Convenient
  3. Less memory

The python numpy is choosing because array occupies less memory as compared to the list.
It is pretty and fast in the execution and at same time it is convenient to work with numpy.

Inspect the size and shape of a numpy array:-

Every array in the python has the properties and wants to understand in order to know the array.
Consider the single dimensional array and 2dimentional array as it is created from the list and has 2 dimensional arrays shows rows and column like the matrix.
The creation of the zeros and ones of the numpy arrays:-
The matrix of zeros and ones using the np.zeros and np.one command is used.
It is also used when you initialize the weight during the first iteration.
The syntax is as follows:-
Numpy Zero

numpy.zeros (shape, dtype=float, order='C')

Example numpy zero with datatype :-

Import numpy as np
np.zeros((1,2))

Output:

array ([[0., 0.],
          [0. 0.]])

Numpy Once

numpy.ones (shape, dtype=float, order='C')

Mathematical and the relational operator for multiple arrays:-
After the array is created we do some operations you can do the numpy operations.

Accessing the elements in array:-

Operations Addition on Array:-

Firstly we take the one dimensional array and they are created as follows,

Example:-

array1=np.array([20,20,30,70,40])

array2=np.array([10,20,20,30,40])

Now you can perform arithmetic operations on these arrays.
If you add the arrays, the arithmetic operator will work on element and the output will be an array of the same dimension.

Example:-

Array3=array1+array2
Array3
Output:
Array ([30, 40, 50, 100, 80])

Subtraction on Array Example :-

array1=np.array ([20, 20, 30, 70, 40])

array2=np.array ([10, 20, 20, 30, 40])

Now you can perform arithmetic operations on these arrays.
If you subtraction of the arrays, the arithmetic operator will work on element and the output will be an array of the same dimension.
Example:-
Array3=array1-array2
Array3
Output:
Array3= ([10, 00, 10, 50, 00])

Multiplication on Array Example :-

array1=np.array ([20, 20, 30, 70, 40])

array2=np.array ([10, 20, 20, 30, 40])

Now you can perform arithmetic operations on these arrays.
If you Multiplication of the arrays, the arithmetic operator will work on element and the output will be an array of the same dimension.
Example:-
Array3=array1*array2
Output:
array3 ([200,400,600,210,800])

Division on Array Example :-

array1=np.array ([20, 20, 30, 70, 40])

array2=np.array ([10, 20, 20, 30, 40])

Now you can perform arithmetic operations on these arrays.
If you division of the arrays, the arithmetic operator will work on element and the output will be an array of the same dimension.
Example:-
Array3=array1/array2
Output:
Array3 ([2, 1, 15, 23, 00])
For the following conditions consider the array a [1, 2, 1, 1, 1]

Compute Exponent of an array:-

 

np.exp(a)
array([2.71828183, 7.3890561 , 2.71828183, 2.71828183, 2.71828183])

Compute Square Root of an array:-

 

np.sqrt(a)
Array ([2, 4, 2, 2, 2])

Compute Sine/Cosine:-

 

np.sin(a)
array([0.84147098, 0.90929743, 0.84147098, 0.84147098, 0.84147098])

To Take Logarithm:-

 

np.log(a) 
Array ([0, 0.69314718, 0, 0, 0])

 

np.log2(a) 
Array ([0, 1, 0, 0, 0])

To Take Dot Product:-

 

a.dot(b)
32

To Round an Array :-

 

 

 

np.random.seed(42)
a = np.random.rand(5)
print(a)
[0.37454012 0.95071431 0.73199394 0.59865848 0.15601864]
np.around(a)
Array ([0, 1, 1, 1, 0.])

Arithmetic Operators with Numpy 2D Arrays :-

Create the two dimensional array a and b
a=np.array ([3, 2], [0, 1])
b=np.array ([3, 1], [2, 1])
Then print (a)
Output:-
[3, 2]
[0, 1]
Then print (b)
Output:-
[3, 1]
[2, 1]
Addition of two arrays:-
A+b
Output:-
Array ([6,3],[2,2])

Multiplication of two arrays :-

A*b
Output:-
Array ([9, 2], [0, 1])
Matrix Multiplication of two arrays :-
a@b
Array ([13, 5], [2, 1])
Functions of the multidimensional array:-
The functions used in the single dimension array are different from the multidimensional arrays.
The functions in the multidimensional array are as follows:-
Transpose ()
Dialogue ()
Flatten ()
Sort ()
Etc.
If we create a new matrix it has rows as the column of the original matrix and the vice versa.
We write a program to convert the given list into a flattened list in python.
Example:-
From itertools import chain
Ini_list=[[1,3,2],[3,2,5],[7,5,4]]
Finallist is:-[1,3,2,3,2,5,7,5,4]
Example below shows the basic operations on array:-
Array
array1= ([100,200,300]
array2= ([400,500,600])

Additional Services : Refurbished Laptops Sales, Python Classes, Share Market Classes And SEO Freelancer in Pune, India