![]() |
VOOZH | about |
In Python, matrices can be represented as 2D lists or 2D arrays. Using NumPy arrays for matrices provides additional functionalities for performing various operations efficiently. NumPy is a Python library that offers fast, optimized array operations.
Performing element-wise operations allows you to directly apply arithmetic operations between matrices of the same shape.
Output
The element wise addition of matrix is:
[[ 8 10]
[13 15]]
The element wise subtraction of matrix is:
[[-6 -6]
[-5 -5]]
The element wise division of matrix is:
[[0 0]
[0 0]]
Use np.multiply() for element-wise multiplication and np.dot() or @ for standard matrix multiplication.
Output
Element-wise multiplication of matrix is:
[[7 16]
[36 50]]
Matrix multiplication:
[[25 28]
[73 82]]
NumPy provides utility functions to perform common matrix operations like square root, sum, or transpose.
Output
The element wise square root is:
[[ 1. 1.41421356]
[ 2. 2.23606798]]
The summation of all matrix element is: 34
The column wise summation of all matrix is: [16 18]
The row wise summation of all matrix is: [15 19]
The transpose of given matrix is:
[[1 4]
[2 5]]
If you are not using NumPy, you can perform matrix operations using nested loops:
Output
Addition:
[[8, 10], [13, 15]]Subtraction:|
[[-6, -6], [-5, -5]]Division:
[[0.14285714285714285, 0.25], [0.4444444444444444, 0.5]]