Answer the question
In order to leave comments, you need to log in
Python nxn matrix determinant?
How to write a program to find the determinant of an nxn matrix without third-party libraries?
Here is the code
import pandas as pd
a, b, c = 0, 0, 0
print('Выберите действие от 1 до 6: 1 сложение, 2 вычитание, 3 умножение, 4 деление, 5 транспонирование и 6 определитель')
a = int(input())
if a < 5:
print('введите числа')
b = int(input())
c = int(input())
if a == 1:
print(b+c)
if a == 2:
print(b-c)
if a == 3:
print(b*c)
if a == 4:
print(b-c)
else:
print('введите размерность матрицы')
b = int(input())
c = int(input())
mat = {}
for row in range(b):
print(f'Строка {row}')
for column in range(c):
mat[row, column] = input()
if a == 5:
for column in range(c):
str = ''
for row in range(b):
str += mat[row, column] + ', '
print(str[:-2])
if a == 6:
# создаем df для удобства
df = pd.DataFrame()
for row in range(b):
for column in range(c):
df.loc[row, column] = int(mat[row, column])
# получаем матрицу треугольного вида
for column in range(b):
for row in range(column+1, b):
df.loc[row, :] = df.loc[column, :] * (- df.loc[row, column] / df.loc[column, column]) + df.loc[row, :]
# Находим детерминант
det = 1
for row in range(b):
det *= df.loc[row, row]
print(det)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question