Re: [Numpy-discussion] setting the attributes of an array of object

2007-10-16 Thread Sebastian Haase
Hi,
there is a way of doing this. As far as I know, you have to create
your own version of numpy arrays. E. g. try this:
class myNumpy(numpy.ndarray):
 pass

Then creating an instance as in
a = myNumpy(otherNumpyArray)

would make `a` behave just like any other array, except that you CAN
attach attributes to it.

Be carefull that some (many / most ?) operations on that array will
return you a normal numpy array again.

I don't understand the reasons behind all of this.

HTH,
Sebastian Haase


On 9/29/07, jelle [EMAIL PROTECTED] wrote:
 Hi,

 I'm wondering whether i can re-write the following idiom with numpy arrays:

 for i in some_list:
   i.some_attr = some_value

 it would be wonderful if one was able to write this idiom as

 arr[just_these].some_attr = some_value
 or
 setattr(arr[just_these], 'some_attr', some_value)

 since often expensive loops through lists of object could be avoided.

 any thoughts on this are much appreciated,

 thanks,

 -jelle

 ___
 Numpy-discussion mailing list
 Numpy-discussion@scipy.org
 http://projects.scipy.org/mailman/listinfo/numpy-discussion

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] setting the attributes of an array of object

2007-10-16 Thread Pierre GM
On Tuesday 16 October 2007 11:47:35 Sebastian Haase wrote:
 Hi,
 there is a way of doing this. As far as I know, you have to create
 your own version of numpy arrays. E. g. try this:
...
 Be carefull that some (many / most ?) operations on that array will
 return you a normal numpy array again.

 I don't understand the reasons behind all of this.

Maybe
http://www.scipy.org/Subclasses
could give you some hints ?
___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] setting the attributes of an array of object

2007-10-16 Thread Travis E. Oliphant
Sebastian Haase wrote:
 Hi,
 there is a way of doing this. As far as I know, you have to create
 your own version of numpy arrays. E. g. try this:
 class myNumpy(numpy.ndarray):
  pass

 Then creating an instance as in
 a = myNumpy(otherNumpyArray)

 would make `a` behave just like any other array, except that you CAN
 attach attributes to it.

 Be carefull that some (many / most ?) operations on that array will
 return you a normal numpy array again.

 I don't understand the reasons behind all of this.
   

The __array_priority__  attribute determines who wins when two 
different sub-classes are involved in an operation.   The ndarray has a 
priority of 0.0.

-Travis

___
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion