1
I have the following vector:
a = [10, 20, 30, 40...]
I need to create a new list that is the subtraction of the second index by the first, the third index by the first and so on... Then the third index by the second, fourth index by the third and so on. For example:
b = [índice[1] - índice[0], índice[2] - índice[0], índice[3] - índice[0], índice[2] - índice[1], índice[3] - índice[1]...]
That is, I need to iterate all conditions, but always in this logic the subsequent index less the previous one.
I have the script below, but it does not iterate all conditions.
a = [10, 50, 30, 5]
b = [a[i+1]-a[i] for i in range(0, len(a)) if i+1 < len(a)]
print (b)
I’m sorry, in case I haven’t been very clear. I tried to be awesome!
Someone could help me?
It is not very clear which indexes will be subtracted. Do you need to subtract 0 from all elements i > 0, subtract 1 from all elements i > 1, subtract 2 from all elements i > 2, etc.? And what exactly is the difference to this question (https://answall.com/q/230085/5878)?
– Woss
That’s right! What I need. The difference to this quoted question is that I am making the Indice[1] - Indice[0], then index[4]-index[3]. I need it to index[1]- index[0], then index[2] - index[0] and index[3]-index[0]. That is, it is as if I were to catch the index[0] and perform the subtraction procedures. When it reached its end, it jumped to the index[1], and did the same with the index[2] and index[3] and so on. I was able to explain it to you better? I’m sorry for anything.
– Danilo