【发布时间】:2011-03-04 18:27:58
【问题描述】:
下面的例子展示了我想要做什么:
>>> test
rec.array([(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0),
(0, 0, 0), (0, 0, 0), (0, 0, 0), (0, 0, 0)],
dtype=[('ifAction', '|i1'), ('ifDocu', '|i1'), ('ifComedy', '|i1')])
>>> test[['ifAction', 'ifDocu']][0]
(0, 0)
>>> test[['ifAction', 'ifDocu']][0] = (1,1)
>>> test[['ifAction', 'ifDocu']][0]
(0, 0)
所以,我想将值 (1,1) 分配给 test[['ifAction', 'ifDocu']][0]。 (最终,我想做test[['ifAction', 'ifDocu']][0:10] = (1,1) 之类的事情,为0:10 分配相同的值。我尝试了很多方法,但从未成功。有什么办法吗?
谢谢你, 俊
【问题讨论】:
-
另见@HYRY 的answer to a slightly different question,它为这个问题提供了很好的解决方案。
标签: python numpy slice recarray