[Numpy-discussion] Numpy inverse giving incorrect result

shbr s.a.brown at ncl.ac.uk
Wed May 23 05:22:10 EDT 2012


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-tp33894469p33894469.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.




More information about the NumPy-Discussion mailing list