I have a question that is similar to the one posted here, but their solution is not working for this case. Here is a code snippet:
import numpy as np
x = np.arange(-5, 6)
y = np.sqrt(x)[np.logical_not(np.isnan(x))]
print(y)
Output
[ nan nan nan nan nan 0.
1. 1.41421356 1.73205081 2. 2.23606798]
C:\Users\gmbra\Downloads\Python Programs\Mechanisms\scratch.py:4: RuntimeWarning: invalid value encountered in sqrt
y = np.sqrt(x)[np.logical_not(np.isnan(x))]
The np.logical_not
is not working as expected. What was expected was an array with no nan
values. On a side note, how can I remove the warning given from trying to take the square root of a negative number?
I would like to add that I will be performing other operations which will produce nan
values. I just want to ignore those.