I have an array containing some negative values. how can i find the absolute value?
for eg suppose my array is
arr = [-2,-5,0,1,2]
and i want an array
arr_out =[2,5,0,1,2]
I have an array containing some negative values. how can i find the absolute value?
for eg suppose my array is
arr = [-2,-5,0,1,2]
and i want an array
arr_out =[2,5,0,1,2]
Without numpy
using list comprehension:
arr = [-2,-5,0,1,2]
arr_out = [abs(i) for i in arr]
print(arr_out)
Output:
[2, 5, 0, 1, 2]