I want to do a calculation and append to total_xh only the coordinates x for which the condition on the sum is met. Since I don't know a priori if this condition will be met, I save first the coordinates x to a temporaty list xh. Then if condition on sum is met I save xh into another list, total_xh. This way I have all the coordinates x for which the condition was met. The problem I have is that, the total_xh, is a list of all the previous lists, while I want an array containing all the coordinates x. intt = data[1:len(data), 6] tst = [] xh = [] total_xh = [] for i in range(1, len(data)-1): if intt != 0: tst.append(np.sqrt(x-x[i-1]))**2.0)) xh.append(x) else: if sum(tst) < 2: total_xh.append(np.array(xh)) xh = [] continue total_xh = np.array(total_xh) Continue reading...