On Saturday 29 January 2011 03:32:22 Robert Kern wrote: > You catch the exception with a try: except: suite just like > you would in any other program. > > try: > result = la.inv(amatrix) > except la.LinAlgError, e: > printline("%s: %s" % (type(e).__name__, e)) > else: > printline('\n inverse') > ... > self.finished = True > > > http://docs.python.org/tutorial/errors.html#handling-exceptio > ns
Robert, I've changed the code exactly as you have suggested. Here is the listing of the snippet of code now: for i in range(dim): line = fin.readline().strip().split() print line for j in range(dim): amatrix[i, j] = float(line[j]) try: result = la.inv(amatrix) except la.LinAlgError, e: printline("%s: %s" % (type(e).__name__, e)) else: printline('\n inverse') self.printer(printline, result) printline('\n unit matrix expected') i = np.dot(amatrix, result) self.printer(printline, i) self.finished = True The result is that the program now does exactly what I wanted it to do. Thank you for the simple and straight answer - brilliant in its simplicity. Dumb of me not to think of it in the first place - apologies for the noise to all and particularly to Michael Thompson. Now to the question of what to do about the inversion errors NOT recognised by the "la.inv", viz for singular 3x3 and 4x4 matrices and others not yet tried, questions for me to ponder. Any suggestions in that area? Old and chastised Al. -- Algis http://akabaila.pcug.org.au _______________________________________________ PySide mailing list PySide@lists.openbossa.org http://lists.openbossa.org/listinfo/pyside