0

I am trying to access to a structured array line by line by iterating on the values of one field of it but even if the value iterate well, the slice of the array doesn't change. Here is my SWE :

import numpy as np
dt=np.dtype([('name',np.unicode,80),('x',np.float),('y',np.float)])
a=np.array( [('a',0.,0.),('b',0.,0.),('c',0.,0.) ],dtype=dt)
for n in a['name']:
  print n,a['name'==n]

gives me :

a (u'a', 0.0, 0.0)
b (u'a', 0.0, 0.0)
c (u'a', 0.0, 0.0)

At each iteration, I always have the same slice of the array... strange ?

Sigmun
  • 1,002
  • 2
  • 12
  • 23

1 Answers1

4

The last line is not right. The array index evaluates to True or False rather than doing a lookup of a named column. Try this:

for n in a['name']:
    print n,a[a['name']==n]
Christian K.
  • 2,785
  • 18
  • 40
  • The problem is, like I post in another thread, I cannot modify the array that way http://stackoverflow.com/questions/36693399/how-to-modify-one-column-of-a-selected-row-from-a-numpy-structured-array – Sigmun Apr 18 '16 at 13:13
  • What kind of modification do you need to do in addition to what you found out yourself in the other post? – Christian K. Apr 18 '16 at 13:28
  • Don't worry, it was something wrong in the given answer. – Sigmun Apr 18 '16 at 13:55