det
Syntax
det(X)
Details
Return the determinant of matrix X. Null values are replaced with 0 in the calculation.
DolphinDB’s det function and NumPy’s
numpy.linalg.det have the same core functionality, but differ
in parameter design and handling of missing values.
- DolphinDB’s
detrequires the input to be a matrix object, whereasnumpy.linalg.detaccepts array-like inputs and automatically converts them tondarray. - In terms of missing value handling, DolphinDB’s
dettreats NULL values as 0, whilenumpy.linalg.detreturns NaN or Inf when the input contains NaN or Inf values. See the examples below for details.
Parameters
X is a matrix.
Returns
A DOUBLE scalar.
Examples
x=1..4$2:2;
x;
| #0 | #1 |
|---|---|
| 1 | 3 |
| 2 | 4 |
x.det();
// output: -2
x=1 2 3 6 5 4 8 7 0$3:3;
x;
| #0 | #1 | #2 |
|---|---|---|
| 1 | 6 | 8 |
| 2 | 5 | 7 |
| 3 | 4 | 0 |
det(x);
// output: 42
x=1 2 3 6 5 4 8 7 NULL $3:3;
x;
| #0 | #1 | #2 |
|---|---|---|
| 1 | 6 | 8 |
| 2 | 5 | 7 |
| 3 | 4 |
det(x);
// output: 42
The following code is executed in Python and demonstrates how NumPy’s
numpy.linalg.det handles NaN and Inf
values.import numpy as np
A = np.array([
[1, 6, 8],
[2, 5, 7],
[3, 4, np.nan]
])
print(np.isnan(np.linalg.det(A)))
# Return: True
B = np.array([
[1, 6, 8],
[2, 5, 7],
[3, 4, np.inf]
])
print(np.isnan(np.linalg.det(B)))
# Retur True