Python: Why does the for loop order not work for this matrix problem?
So what I'm trying to solve is the following problem: Find the minimum value for exponent n so that A^n = 0. A is a 5x5 matrix as you can see below.
I have tried this code in python so far and for some reason the "for loop" doesn't seem to work in this case (which I also don't know why); A is already defined:
import numpy as np
A = np.array([[2., 2., 2., 2., -4.], [7., 1., 1., 1., -5.], [1., 7., 1., 1., -5.], [1., 1., 7., 1., -5.], [1., 1., 1., 7., -5.]])
from numpy.linalg import matrix_power
i = A
a = matrix_power(i, n) for n in range(10) <- this doesn't seem to work, also I'm just
guessing a range here...
c = a.max()
b = a.min()
if (b == c == 0):
print(n)
I would highly appreciate your help! I'm a student that is working with python for the first time so my skills are still very basic.
from Recent Questions - Stack Overflow https://ift.tt/3tZfgjy
https://ift.tt/eA8V8J
Comments
Post a Comment