I have a bunch of numpy arrays that have both positive and negative numbers in them and I want to find the number closest to zero in each array not the smallest number. I also want to retain the signs of the numbers. Example below:
array1 = np.array([5, 3.2, -1.2, -0.2, 7])
array2 = np.array([19, -20, -4.7, 6, 9, 42])
array3 = np.array([4, 0.3, -9, 8, 6, 14])
Ideal output would be something that give me the number closest to zero, so for each array respectively it would be:
"Closest to zero for array 1:" -0.2
"Closest to zero for array 2:" -4.7
"Closest to zero for array 3:" 0.3
Is there any way to do this?