I'm populating an array, reading data from file:
Input:
2
4
-8
5
-2
Code:
f = [ i.strip() for i in open('file.txt', 'r') ]
a = []
for line in f:
line = line.split()
a.append(float(line[0]))
that produces the vector a=[2,4,-8,5,-2]. Now I want to replace all negative values with their values +10, in order to obtain a vector b=[2,4,2,5,8]. Without using a loop or a for cycle, how can I do that? I tried both using the np.where() function and the a[a<0], but they don't produce any result (they just work if I create a np.array[2,4,-8,5,-2] ex novo...). Thank you in advance.
i.strip() for...loop?