I found a strange situation with my code and the issue is shown in the code bellow
import numpy as np
dt = dict(names = ['n1','n2'], formats = ['a8','int'])
reca = np.recarray((10,), dtype = dt)
reca['n1'] = ['a','b','c','d','e','f','g','e','f','g']
reca['n2'] = range(10)
sreca = reca[::2]
print sreca[0] in reca
sreca[0]['n2'] = 12
print sreca[0] in reca
ireca = reca[[1,3,5,7]]
print ireca[0] in reca
ireca[0]['n2'] = 7
print ireca[0] in reca
The output is:
True
True
True
False
To my understand, either sreca
or ireca
should keep a reference of reca
unless i assign a new value to them directly, but ireca
lost its reference after the assignment. I don't know if this is expected or not.
Could any one advice me how to avoid this?
BTW, I found that a small change of the code (reca['n1'] = ['a']*10
for example) will give me all True
in this sample, this really make me confused.