
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Compute the multiplicative inverse of a matrix in Python
To compute the (multiplicative) inverse of a matrix, use the numpy.linalg.inv() method in Python. Given a square matrix a, return the matrix ainv satisfying dot(a, ainv) = dot(ainv, a) = eye(a.shape[0]). The method returns (Multiplicative) inverse of the matrix a. The 1st parameter, a is a Matrix to be inverted.
Steps
At first, import the required libraries-
import numpy as np from numpy.linalg import inv
Create an array −
arr = np.array([[ 5, 10], [ 15, 20 ]])
Display the array −
print("Our Array...\n",arr)
Check the Dimensions −
print("\nDimensions of our Array...\n",arr.ndim)
Get the Datatype −
print("\nDatatype of our Array object...\n",arr.dtype)
Get the Shape −
print("\nShape of our Array object...\n",arr.shape)
To compute the (multiplicative) inverse of a matrix, use the numpy.linalg.inv() method in Python −
print("\nResult...\n",np.linalg.inv(arr))
Example
import numpy as np from numpy.linalg import inv # Create an array arr = np.array([[ 5, 10], [ 15, 20 ]]) # Display the array print("Our Array...\n",arr) # Check the Dimensions print("\nDimensions of our Array...\n",arr.ndim) # Get the Datatype print("\nDatatype of our Array object...\n",arr.dtype) # Get the Shape print("\nShape of our Array object...\n",arr.shape) # To compute the (multiplicative) inverse of a matrix, use the numpy.linalg.inv() method in Python. print("\nResult...\n",np.linalg.inv(arr))
Output
Our Array... [[ 5 10] [15 20]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Result... [[-0.4 0.2] [ 0.3 -0.1]]
- Related Articles
- Compute the multiplicative inverse of a matrix object with matrix() in Python
- Compute the multiplicative inverse of more than one matrix at once in Python
- PyTorch – How to compute the inverse of a square matrix?
- Modular multiplicative inverse in java
- Multiplicative Inverse In Rational Number
- Compute the inverse Hyperbolic sine in Python
- Compute the inverse Hyperbolic cosine in Python
- Compute the inverse Hyperbolic tangent in Python
- What is Additive inverse and Multiplicative inverse?
- Compute the inverse cosine with scimath in Python
- Compute the inverse sine with scimath in Python
- The multiplicative inverse of $\frac{-3}{6}$ is____.
- Compute the inverse Hyperbolic sine of array elements in Python
- Compute the inverse of an N-dimensional array in Python
- Compute the inverse Hyperbolic tangent of array elements in Python

Advertisements