Метод numpy.linalg.det() используется в Python для вычисления определителя входной матрицы.
Содержание
Синтаксис
|
1 2 |
numpy.linalg.det(array) |
Параметры
Функция np.linalg.det() принимает в качестве параметра только один аргумент — имя массива.
Возвращаемое значение
Он возвращает определитель данного массива. Возвращаемое значение будет иметь тип данных float.
Пример 1: как работает метод numpy.linalg.det()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import numpy as np # This will create a 2D array of shape 2x2 with values 5 to 8 arr = np.arange(5, 9).reshape(2, 2) print("The array is:\n", arr) print("Shape of the array is : ", np.shape(arr)) # Now we will print determinant using det() function print("Determinant of the given array: ", np.linalg.det(arr)) # Verify with the manual caculation detr =(5*8)-(7*6) print("Determinant using manual method: ", detr) |
Выход
|
1 2 3 4 5 6 7 |
The array is: [[5 6] [7 8]] Shape of the array is :(2, 2) Determinant of the given array: -2.000000000000005 Determinant using manual method: -2 |
Пример 2: как использовать метод np.linalg.det()
|
1 2 3 4 5 6 7 8 9 10 11 12 13 |
import numpy as np # This will create a 2D array of shape 3x3 with values 1 to 9 arr = np.arange(1, 10).reshape(3, 3) print("The array is:\n", arr) print("Shape of the array is : ", np.shape(arr)) # Now we will print determinant using det() function print("Determinant of the given array: ", np.linalg.det(arr)) # Verify with the manual caculation detr = 1*(5*9 - 6*8) + 2*(4*9 - 6*7) - 3*(4*8 - 5*7) print("Determinant using manual method: ", detr) |
Выход
|
1 2 3 4 5 6 7 |
The array is: [[1 2 3] [4 5 6] [7 8 9]] Shape of the array is :(3, 3) Determinant of the given array: 0.0 Determinant using manual method: -6 |
