Ask Your Question
1

What modifications can be made to this condition in order to substitute infinite and NaN values?

asked 2022-12-29 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-08-12 20:00:00 +0000

nofretete gravatar image

To substitute infinite and NaN values, the condition can be modified as follows:

import numpy as np

arr = np.array([1, 3, 0, 5, np.nan, np.inf, -np.inf])

# substitute NaN with 0
arr[np.isnan(arr)] = 0

# substitute infinite values with large finite value (e.g. 10^9)
arr[np.isinf(arr)] = 10**9

print(arr)

Output:

[1.e+00 3.e+00 0.e+00 5.e+00 0.e+00 1.e+09 1.e+09]

This code substitutes NaN values with 0 and infinite values with a large finite value (e.g. 10^9).

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-12-29 11:00:00 +0000

Seen: 8 times

Last updated: Aug 12 '21