Skip to content
Advertisement

Numpy array: iterate through column and change value based on the current value and the next value

I have an array like this: This is an extension of a recent question that I asked elsewhere here. I have a numpy array like this:

JavaScript

In the third column, I want the value to be replaced with 10001 if the next one along is 101 AND if the current one is 6. which would result in an array like this:

JavaScript

Any help on this would be greatly appreciated! Thanks!

Advertisement

Answer

One way using numpy.roll:

JavaScript

Output:

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement