I have an array of the type:
import numpy as np
mi_array = np.array([1,2,3])
Now, given a certain starting value, for example 100, I would like to calculate the array that is formed by subtracting the subsequent value from the result of the previous subtraction. That is, I would like to get the result of:
100 - 1, 99 - 2, 97 - 3
That is, the array[99, 97, 94]
I have tried the following.
import numpy as np
a= np.array([1,2,3])
def resta_iterativa(value):
result = []
for i in a:
resta = value - i
result.append(resta)
return result
print(resta_iterativa(100))
The goal is to get a more efficient code, and one that works.