I'm trying to emulate Cramer's rule for indefinite number of variables. This is what I have so far
def cramers(n)
matrix = []
for i in range(0, n):
matrix.append([])
for j in range(0, n+1):
matrix[i].append(0)
matrix[i][j] = float(input("V" + str(i+1) + str(j+1) + ": "))
#n = 2, V11 = 1, V12 = 2, V13 = 3, V21 = 4, V22 = 5, V23 = 6
mat = np.array(matrix)
matA = mat[0:n, 0:n]
matB = mat[0:n, n:]
matATrans = matA.transpose()
matBTrans = matB.transpose()
for n = 2, these are sample input values of matATrans and matBTrans:
matATrans = [[1. 4.], [2. 5.]]
matBTrans = [3. 6.]
My question is, how can I produce a numpy array, mat, with n = 2 length for instance, whose value contains this?
mat = [[[3. 6.],[2. 5.]],[[1. 4.],[3. 6.]]]
Basically, the (n-1)th element of matATrans is replaced by matBTrans. I'm thinking it could be done using a forloop. This was my attempt.
for i in range(n):
matATrans[i] = matBTrans
print(matATrans)
The result is this:
[3. 6.],[2. 5.]
[3. 6.],[3. 6.]
Obviously, it's wrong because the content of matATrans has been altered in the first loop. Also, it still isn't appended to a mat matrix.
Please enlighten me. Thanks