Home > Mobile >  Adding the last position of an array to the same array
Adding the last position of an array to the same array

Time:01-01

In matlab one can do

for i:2:10 array(i) = array(i-1) value; end

How can I replicate this in python?

CodePudding user response:

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.

CodePudding user response:

You can do something like this in python:

But you should also pay attention to one point: That the number of indexes in Python starts from zero while in MATLAB from one

for i in range(2,10):
    array[i] = array[i-1]   value

have a good time!

  • Related