Lets say your numpy array is:
A = [1,1,2,3,4]
You can simply do:
A + .1
to add a number to tha
In [43]: A = np.array([1,1,2,3,4], dtype = 'float')
In [44]: A[::2] += 0.1
In [45]: A
Out[45]: array([ 1.1, 1. , 2.1, 3. , 4.1])
Note that this modifies A
. If you wish to leave A
unmodified, copy A
first:
In [46]: A = np.array([1,1,2,3,4], dtype = 'float')
In [47]: B = A.copy()
In [48]: B[::2] += 0.1
In [49]: B
Out[49]: array([ 1.1, 1. , 2.1, 3. , 4.1])
In [50]: A
Out[50]: array([ 1., 1., 2., 3., 4.])