[Numpy-discussion] returning recarray records as plain arrays
Matthew Koichi Grimes
mkg at cs.nyu.edu
Wed Jan 3 23:57:43 EST 2007
Pierre GM wrote:
> On Wednesday 03 January 2007 15:39, Matthew Koichi Grimes wrote:
>
>> As per Stefan's help, I've made a subclass of recarray called nnvalue.
>> It just fixes the dtype to [('x', 'f8'), ('dx', 'f8'), ('delta', 'f8)],
>> and adds a few member functions. I basically treat nnvalue as a struct
>> with three equal-shaped array fields: x, dx, and delta.
>>
>
> Matthew,
> Please try to post (pieces of) your code, so that we can have a better idea of
> how to help you.
> Thanks in advance
> P.
>
It's essentially unchanged from Stefan's code:
import numpy as N
class nnvalue(N.recarray):
dtype = N.dtype([('x','f8'),('dx','f8'),('deltas','f8')])
def __new__(subtype,shape):
data = N.zeros(shape,subtype.dtype)
return data.view(subtype)
def __array_finalize__(self,obj):
pass # for now
def clearGradient(self):
"""Fills all members other than x with zeros."""
self['dx'][:] = 0.
self['deltas'][:] = 0.
More information about the NumPy-Discussion
mailing list