下面的例子显示了我想做的事:的Python NumPy的结构数组(recarray)分配值成片
>>> 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 [回答稍微不同的问题](http://stackoverflow.com/a/21819324/347815),它可以很好地解决这个问题。 – katahdin 2014-06-09 14:42:02