There is:

Copyfrom numpy import inf
x[x == -inf] = 0
Answer from pv. on Stack Overflow
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.5.dev0 Manual
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
🌐
AskPython
askpython.com › home › usage of nan_to_num in replacing nan and infinity
Usage of nan_to_num in replacing NaN and Infinity - AskPython
February 23, 2023 - The presence of such values can cause errors in calculations in a data analysis project. The function nan_to_num can eradicate these values making your project error-free. This function is available in the NumPy library and can also be used ...
🌐
Note.nkmk.me
note.nkmk.me › home › python › numpy
NumPy: Replace NaN (np.nan) using np.nan_to_num() and np.isnan() | note.nkmk.me
January 23, 2024 - Note that filling with the mean of the non-NaN values is not possible during the initial read with np.genfromtxt(). For this, refer to the method described below. You can use np.nan_to_num() to replace NaN. ... Note that np.nan_to_num() also ...
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.1 Manual
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.4 Manual
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
🌐
TutorialsPoint
tutorialspoint.com › replace-infinity-with-large-finite-numbers-but-fill-nan-values-in-python
Replace infinity with large finite numbers but fill NaN values in Python
February 25, 2022 - To replace NaN with zero and infinity with large finite numbers, use the numpy.nan_to_num() method in Python. The method returns, x, with the non-finite values replaced. If copy is False, this may be x itself. The 1st parameter is the input data. The 2nd parameter is copy, whether to create ...
🌐
bioinfo core
bioinfocore.com › home › python › python numpy replace nan in array to 0 or a number
numpy array replace nan inf to 0 or number | bioinfo core
October 21, 2021 - a = numpy.array([1,2,3,4,np.nan]) # if copy=False, the replace inplace, default is True, it will be changed to 0 by default a = numpy.nan_to_num(a, copy=True) # if you want it changed to any number, eg.
Find elsewhere
🌐
Finxter
blog.finxter.com › 5-best-ways-to-replace-infinity-with-large-finite-numbers-and-fill-nan-values-in-python
5 Best Ways to Replace Infinity with Large Finite Numbers and Fill NaN Values in Python – Be on the Right Side of Change
March 1, 2024 - This example starts by obtaining the maximum finite float number representable by NumPy to replace ‘inf’ values. Using a boolean mask with np.isinf, the ‘infinity’ values in the array are replaced. To handle ‘NaN’ values, np.nan_to_num is called, which fills ‘NaN’ with the specified fill value.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.3 Manual
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
🌐
NumPy
numpy.org › doc › 1.16 › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v1.16 Manual
February 18, 2020 - If x is inexact, NaN is replaced by zero, and infinity and -infinity replaced by the respectively largest and most negative finite floating point values representable by x.dtype.
🌐
GeeksforGeeks
geeksforgeeks.org › python › replace-infinity-with-large-finite-numbers-and-fill-nan-for-complex-input-values-using-numpy-in-python
Replace infinity with large finite numbers and fill NaN for complex input values using NumPy in Python - GeeksforGeeks
May 3, 2022 - ... # import package import numpy ... # Datatype of the array print("Datatype of our Array is : ",array.dtype) # np.nan is replaced with 1000 and # infinity is replaced with a large positive number print("After replacement the ...
🌐
w3resource
w3resource.com › python-exercises › pandas › python-pandas-data-frame-exercise-52.php
Pandas: Remove infinite values from a given DataFrame - w3resource
import pandas as pd import numpy as np df = pd.DataFrame([1000, 2000, 3000, -4000, np.inf, -np.inf]) print("Original DataFrame:") print(df) print("Removing infinite values:") df = df.replace([np.inf, -np.inf], np.nan) print(df)
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.nan_to_num.html
numpy.nan_to_num — NumPy v2.0 Manual
Replace NaN with zero and infinity with large finite numbers (default behaviour) or with the numbers defined by the user using the nan, posinf and/or neginf keywords.
🌐
GeeksforGeeks
geeksforgeeks.org › python-numpy-replace-nan-with-zero-and-fill-positive-infinity-for-complex-input-values
Python NumPy - Replace NaN with zero and fill positive infinity for complex input values - GeeksforGeeks
April 25, 2022 - In this article, we will cover how to replace NaN with zero and fill negative infinity values in Python using NumPy. Example Input: [ nan -inf  5.] Output: [0.00000e+00 9.99999e+05 5.00000e+00] Explanation: Replacing NaN with 0 and negative inf with any value.