0

How do I find the rows(indices) of my array, where its values change?

for example I have an array:

0 -0.638127 0.805294    1.30671
1 -0.638127 0.805294    1.30671
2 -0.085362 0.523378    0.550509
3 -0.085362 0.523378    0.550509
4 -0.323397 0.94502     0.49001
5 -0.323397 0.94502     0.49001
6 -0.323397 0.94502     0.49001
7 -0.291798 0.421398    0.962115

I want a result like:

[0 2 4 7]

I am happy to use existing librarys and I am not limited to anything. All I want are the numbers of the rows. How would I calculate that?

I tried

a = []
for i, row in enumerate(vecarray):
    if i > 0:
        a[i] = vecarray[i] - vecarray[i-1]
        b = np.where(a != 0)

but that gives me IndexError: list assignment index out of range

Adrian_G
  • 143
  • 1
  • 11

1 Answers1

0
arr = [
(-0.638127, 0.805294, 1.30671),
(-0.638127, 0.805294, 1.30671),
(-0.085362, 0.523378, 0.550509),
(-0.085362, 0.523378, 0.550509),
(-0.323397, 0.94502,  0.49001),
(-0.323397, 0.94502,  0.49001),
(-0.323397, 0.94502,  0.49001),
(-0.291798, 0.421398, 0.962115)
]

i = 0
prev_t = None
for t in arr:
    if t != prev_t:
        prev_t = t
        print(i)
    i += 1
Thomas Munk
  • 643
  • 6
  • 24