I have a numpy array atoms.numbers
which looks like:
array([27, 27, 27, 27, 27, 27, 57, 57, 57, 57, 57, 57, 57, 57, 27, 27, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 27, 27, 27, 27, 27, 27, 57, 57, 57, 57, 57,
57, 57, 57, 27, 27, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
I can replace all of the same instance such as every '57' in the array using:
atoms.numbers[atoms.numbers==57]=38
which gives:
array([27, 27, 27, 27, 27, 27, 38, 38, 38, 38, 38, 38, 38, 38, 27, 27, 8,
8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
8, 8, 8, 8, 8, 8, 27, 27, 27, 27, 27, 27, 38, 38, 38, 38, 38,
38, 38, 38, 27, 27, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8])
I would like to be able to replace every nth instance in the array. I have tried:
n=5
atoms.numbers[atoms.numbers==57][::n]=38
Which does not work.