Numpy inverse giving incorrect result

I am running the following script as a basic input-output model but the inverse function is bringing back an incorrect result (I have checked this by inputting the data manually).I am very new to python but I assume the error occurs in how the data is gathered from the csv but I don’t know how to fix this. Any advice would be much appreciated. import numpy from numpy import * from numpy.linalg import * from numpy import genfromtxt conMatrix = genfromtxt("iopy.csv", delimiter=',') print "Consumption Matrix (C)" print conMatrix print "" #print "Consumption Matrix (C)" #manually entered data #conMatrix = numpy.matrix('0.4102 0.0301 0.0257; 0.0624 0.3783 0.1050; 0.1236 0.1588 0.1919') #print conMatrix identityMatrix = numpy.identity(3) print "Identity Matrix (I)" print identityMatrix print "" print "I-C" eyesee = numpy.subtract(identityMatrix, conMatrix) numpy.matrix(eyesee) print eyesee print "" print "(I-C)-1" inv = numpy.matrix(eyesee).I print inv print "" print "(I-C)-1*d" d = numpy.matrix('39.24 60.02 130.65') d.shape = (3,1) print inv*d raw_input() Thank you Shaun -- View this message in context: http://old.nabble.com/Numpy-inverse-giving-incorrect-result-tp33894469p33894... Sent from the Numpy-discussion mailing list archive at Nabble.com.

23.05.2012 11:22, shbr kirjoitti:
I am running the following script as a basic input-output model but the inverse function is bringing back an incorrect result (I have checked this by inputting the data manually).I am very new to python but I assume the error occurs in how the data is gathered from the csv but I don’t know how to fix this. Any advice would be much appreciated.
From your explanation it is unfortunately not clear what actually does not work, and what you would expect as results. Can you clarify?
The inverse certainly gives the correct result:
conMatrix = numpy.matrix('0.4102 0.0301 0.0257; 0.0624 0.3783 0.1050; 0.1236 0.1588 0.1919') eyesee = numpy.eye(3) - conMatrix eyesee.I matrix([[ 1.72033888, 0.10060528, 0.06778402], [ 0.22456355, 1.67684212, 0.22502129], [ 0.30725724, 0.34490452, 1.29205728]]) eyesee.I * eyesee matrix([[ 1.00000000e+00, -3.46944695e-18, 0.00000000e+00], [ 2.42861287e-17, 1.00000000e+00, 0.00000000e+00], [ 2.77555756e-17, 0.00000000e+00, 1.00000000e+00]])
participants (2)
-
Pauli Virtanen
-
shbr