check nan values in a np array

array_has_nan = np.isnan(array_sum)

Here is what the above code is Doing:
1. We create an array of random numbers.
2. We sum the array.
3. We check if the sum is NaN.

The output of the code is:

array_has_nan: True

This means that the sum of the array is NaN.

Why is this happening?

The reason is that one of the values in the array is NaN. When you sum an array with a NaN value, the result is always NaN.

To avoid this problem, you can use the np.nansum() function. This function ignores NaN values when summing an array.

Here’s the code: