下面的例子顯示了我想做的事:的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