Python Numpy Structured Array (recarray) assigning values into slices

Posted by user368877 on Stack Overflow See other posts from Stack Overflow or by user368877
Published on 2010-06-17T02:55:14Z Indexed on 2010/06/17 3:03 UTC
Read the original article Hit count: 286

Filed under:
|
|
|

Hi,

The following example shows what I want to do:

>>> 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)

So, I want to assign the values (1,1) to test[['ifAction', 'ifDocu']][0]. (Eventually, I want to do something like test[['ifAction', 'ifDocu']][0:10] = (1,1), assigning the same values for for 0:10. I have tried many ways but never succeeded. Is there any way to do this?

Thank you, Joon

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy