I have a list and inside of the list, the values and their signs are changing intermittently. I would like to define a function to extract from the list in every two consecutive sign-changing (Let's say zero-crossing points).
n = 5 #a number which comes from another list and here is written to make this example
List_1 = [-1.,-0.89, -0.77,-0.667, -0.55, -0.44,-0.333, -0.22, -0.111,0.,1,1.333,1.66,2,2.3,2.66,3.3, 3.667, 4,-30,-26.77,-23,-20.33-17.11,-13.8,-10,-7.44,-4.22, -1.,30,37.5,45,52.5,60]
def list_excluder:
for i in range(n):
zero_crossings = np.where(np.diff(np.sign(list_1[i])))[0]
GG = list_1[i][zero_crossings[i-1]:zero_crossings[i]]
ls.append(GG)
expected result:
ls = [[-1.,-0.89, -0.77,-0.667, -0.55, -0.44,-0.333, -0.22, -0.111,0.,1,1.333,1.66,2,2.3,2.66,3.3, 3.667, 4],[-30,-26.77,-23,-20.33-17.11,-13.8,-10,-7.44,-4.22, -1.,30,37.5,45,52.5,60.]]