In matlab one can do
for i = 2:10
array(i) = array(i-1) + value
end
How can I replicate this in python?
In python it will be:
for i in range(1,10):
array[i] = array[i-1] + value
Keep in mind that in python, indexing starts from 0.
9? If I understand correctly, matlab's 10 is inclusive, but range isn't, so you need 10 here to stop after index 9 (the 10th 0-indexed element)
valuehere? Is it the old value ofarray(i)?array += valuewhere you have something likek=k+1numpyyou need to initial the array to fill size first. But we need more context to come up with a goodnumpyor python solution. For examplenp.cumsum([value1,value2, value3...]).