# [MATRIX-SIG] FancyArray

**Janko Hauser
**
jhauser@ifm.uni-kiel.de

*Fri, 29 Aug 1997 22:30:47 +0200 (CEST)*

Hi, I haven't played with it yet, but here is a solution to the
reshape problem.
First, reshape does function here, but returns not an UserArray
object.
>>>* a
*UserArray([0, 1, 2, 3, 4, 5, 6, 7, 8])
>>>* reshape(a,(3,3))
*array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
But according to the docs of reshape this is a behavior, which can be
expected in some sense, because reshape returns a copy. reshape is
also not an builtin function, so I see no way to deal with it in the
class itself. But the docs emphasize, that one should use
a.shape=(3,3) for inplace reshaping. This can be handled by the class
with following method:
def __setattr__(self,att,value):
if att == 'shape':
self.__dict__['shape']=value
self.array.shape=value
else:
self.__dict__[att]=value
>>>* c=myUserArray.UserArray(range(9))
*>>>* c
*UserArray
[0 1 2 3 4 5 6 7 8]
>>>* c.shape=(3,3)
*>>>* c
*UserArray
[[0 1 2]
[3 4 5]
[6 7 8]]
>>>*
*
If there are some more drawbacks or wishful things for the UserArray
class, please mention it. I see many useful way to use UserArray, so
this class should be as powerful as possible.
__Janko
_______________
MATRIX-SIG - SIG on Matrix Math for Python
send messages to: matrix-sig@python.org
administrivia to: matrix-sig-request@python.org
_______________