I have a numpy array (say xs), for which I am writing a function to create another array (say ys), which has the same values as of xs until the first half of xs and two times of xs in the remaining half. for example, if xs=[0,1,2,3,4,5], the required output is [0,1,2,6,8,10]
I wrote the following function:
import numpy as np
xs=np.arange(0,6,1)
def step(xs):
ys1=np.array([]);ys2=np.array([])
if xs.all() <=2:
ys1=xs
else:
ys2=xs*2
return np.concatenate((ys1,ys2))
print(xs,step(xs))
Which produces output: `array([0., 1., 2., 3., 4., 5.]), ie the second condition is not executed. Does anybody know how to fix it? Thanks in advance.
if xs.all() <=2:isTruesoys1is assignedxsandys2remains an empty array. On concatenation, you just getys1back which is the same asxs