matrix class
Dan Bishop
danb_83 at yahoo.com
Tue Jun 12 21:20:50 EDT 2007
On Jun 12, 7:31 pm, DarrenWeber <Darren.We... at radiology.ucsf.edu>
wrote:
> Below is a module (matrix.py) with a class to implement some basic
> matrix operations on a 2D list. Some things puzzle me about the best
> way to do this (please don't refer to scipy, numpy and numeric because
> this is a personal programming exercise for me in creating an
> operational class in pure python for some *basic* matrix operations).
>
> 1. Please take a look at the __init__ function and comment on the
> initialization of the list data with respect to unique memory
> allocation.
>
> 2. In the operator overloading of __add__, __sub__, etc., the
> statement isinstance(q, Matrix) raises exceptions every time. This
> statement works fine outside of the class definition, but not during
> the operator evaluation. What is going here?
...
>
> def __add__(self, q):
> 'matrix addition: m3 = m1 + m2'
> # if isinstance(q, Matrix):
> # arg = ("q is not a matrix instance", q)
> # raise TypeError, arg
Wouldn't it make more sense to raise an exception if q is NOT an
instance of Matrix?
More information about the Python-list
mailing list