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 ]]
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.
numpy.zeros (shape, dtype=float, order='C')
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.
Firstly we take the one dimensional array and they are created as follows,
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.
Array3=array1+array2
Array3
Output:
Array ([30, 40, 50, 100, 80])
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])
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])
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) |
Compute Square Root of an array:-
|
np.sqrt(a) |
Compute Sine/Cosine:-
|
np.sin(a) |
To Take Logarithm:-
|
np.log(a) |
|
np.log2(a) |
To Take Dot Product:-
|
a.dot(b) |
To Round an Array :-
|
np.random.seed(42) |