Trying to apply numpy
inbuilt function apply_along_axis
based on row index position
import numpy as np
sa = np.array(np.arange(4))
sa_changed = (np.repeat(sa.reshape(1,len(sa)),repeats=2,axis=0))
print (sa_changed)
OP:
[[0 1 2 3]
[0 1 2 3]]
The function:
np.apply_along_axis(lambda x: x+10,0,sa_changed)
Op:
array([[10, 11, 12, 13],
[10, 11, 12, 13]])
But is there a way to use this function based on row index position
for example, if its a even row index
then add 10
and if its a odd row index
then add 50
Sample:
def func(x):
if x.index//2==0:
x = x+10
else:
x = x+50
return x