[Matrix-SIG] Fibonnaci
Charles G Waldman
cgw@fnal.gov
Tue, 25 May 1999 14:53:01 -0500 (CDT)
Yoon, Hoon (CICG - NY Program Trading) writes:
> Hi,
>
> Iam trying to do Fibonnaci numbers. Obviously I am trying to raise the
> base matrix x to some power p, but I don't know how to do it in one step. I
> would like to call something like x^34.
The problem is that the default __mul__ and __pow__ methods on arrays
multiply the arrays elementwise, rather than as a matrix multiply.
You could define an object with __mul__ and __pow__ methods (and their
"r" versions) to behave as "proper" matrices.
However, you shouldn't have to do this because Numeric provides a
"Matrix" class which does exactly this. I was about to send you an
example of its use, when I made the unpleasant discovery that it's
broken in the current distribution:
buffalo:numeric$ python Matrix.py
Traceback (innermost last):
File "Matrix.py", line 27, in ?
print m*m
File "Matrix.py", line 12, in __mul__
return self._rc(matrixmultiply(self.array, asarray(other)))
AttributeError: _rc
buffalo:numeric$
buffalo:numeric$ python UserArray.py
['_typecode', 'array', 'name', 'shape']
() (100, 100)
Traceback (innermost last):
File "UserArray.py", line 95, in ?
ua_small=ua[:3,:5]
AttributeError: __getitem__
I guess nobody's really been doing much with UserArray :-(
I'll see if I can cook up a quick patch for this....