- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Compute the sign and natural logarithm of the determinant of an array in Python
To Compute the sign and natural logarithm of the determinant of an array, use the numpy.linalg.slogdet() method in Python. The 1st parameter, s is an input array, has to be a square 2-D array.
The method, with sign returns a number representing the sign of the determinant. For a real matrix, this is 1, 0, or -1. For a complex matrix, this is a complex number with absolute value 1, or else 0. The method, with logdet returns the natural log of the absolute value of the determinant. If the determinant is zero, then sign will be 0 and logdet will be -Inf. In all cases, the determinant is equal to sign * np.exp(logdet).
Steps
At first, import the required libraries −
import numpy as np
Create an array −
arr = np.array([[ 1, 2], [ 3, 4]])
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)
The determinant of an array in linear algebra −
print("\nDeterminant...\n",np.linalg.det(arr))
To compute the sign and natural logarithm of the determinant of an array, use the numpy.linalg.slogdet() method in Python. If the determinant is zero, then sign will be 0 and logdet will be -Inf. In all cases, the determinant is equal to sign * np.exp(logdet) −
(sign, logdet) = np.linalg.slogdet(arr) print("\nResult....\n",(sign, logdet))
Example
import numpy as np # Create an array arr = np.array([[ 1, 2], [ 3, 4]]) # 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) # The determinant of an array in linear algebra print("\nDeterminant...\n",np.linalg.det(arr)) # To Compute the sign and natural logarithm of the determinant of an array, use the numpy.linalg.slogdet() method in Python (sign, logdet) = np.linalg.slogdet(arr) print("\nResult....\n",(sign, logdet))
Output
Our Array... [[1 2] [3 4]] Dimensions of our Array... 2 Datatype of our Array object... int64 Shape of our Array object... (2, 2) Determinant... -2.0000000000000004 Result.... (-1.0, 0.6931471805599455)
- Related Articles
- Compute the Natural Logarithm in Python
- Compute the determinant of an array in linear algebra in Python
- Compute the natural logarithm with scimath in Python
- Compute the Natural logarithm for complex-valued input in Python
- Compute the determinant of a Two-Dimensional array in linear algebra in Python
- Compute the determinant for a stack of matrices in linear algebra in Python
- Compute the logarithm base 2 with scimath in Python
- Compute the logarithm base n with scimath in Python
- Compute the logarithm base 10 with scimath in Python
- Return the natural logarithm of one plus the input array element-wise in Numpy
- Compute the inverse of an N-dimensional array in Python
- PyTorch – How to compute the determinant of a square matrix?
- Program to find sign of the product of an array using Python
- Return the base 2 logarithm of the input array in Python
- How to compute the Logarithm of elements of a tensor in PyTorch?
