Matlab vs Python (was RE: Discussion: Introducing new operators for matrix computation)

Paul Prescod paul at prescod.net
Mon Jul 17 20:22:31 EDT 2000


Huaiyu Zhu wrote:
> 
> ...
> 
> That's a good point.  Can __getattr__ be made to work only on a selected
> number of attributes?  We could use it on T, H, I, C for transpose,
> Hermitian transpose, inverse and conjugate.  But if it works on all the
> undefind members the error message may be too obscure.  

I don't think you need __getattr__

class Matrix:
	def __init__( self, ....):
		self.T=Transpose( self )
		self.H=Hermitian( self )
		self.I=Inverse( self )
		self.C=Conjugate( self )
		self.E=Elementwise( self )
		self.M=self # matrixwise is default
	... other matrix-like methods ...

class Transpose:
	def __init__( self, mymatrix ):
		self.mymatrix=mymatrix
	... other matrix-like methods, but transposed ...

Notice that no computation (e.g. actual transposition) needs to be done
until you actually need to calculate a value. Maybe you can find
optimizations that allow only tiny parts of matrices to be computed.
-- 
 Paul Prescod - Not encumbered by corporate consensus
Just how compassionate can a Republican get before he has to leave the 
GOP and join Vegans for Global Justice? ... One moment, George W. Bush
is holding a get-to-know-you meeting with a bunch of gay Republicans.
The next he is holding forth on education or the environment ... It is
enough to make a red-blooded conservative choke on his spotted-owl
drumstick.     - April 29th, Economist




More information about the Python-list mailing list