我必须使用numpy记录数组来保存RAM和快速访问。但我想在这些记录上使用成员函数。例如
X=ones(3, dtype=dtype([('foo', int), ('bar', float)]))
X[1].incrementFooBar()
对于普通的python类,我可以
class QQQ:
...
def incrementFooBar(self):
self.foo+=1
self.bar+=1
pass
X=[QQQ(),QQQ(),QQQ()]
X[1].incrementFooBar()
我怎么能做这样的事,但要不是为了numpy唱片?你知道吗
我可能错了,但我不认为有一种方法可以像那样对numy数组中的记录使用成员函数。或者,您可以非常轻松地构造一个函数来完成相同的任务:
相关问题 更多 >
编程相关推荐