mode.use_inf_as_null 怎么设置 为 true
时间: 2024-05-10 15:17:57 浏览: 8
在代码中,可以使用以下语句将`use_inf_as_null`设置为`True`:
```
import numpy as np
np.seterr(divide='ignore', invalid='ignore', over='ignore')
np.seterr(all='raise', under='warn', over='warn', divide='warn', invalid='warn')
np.seterr(all='ignore', under='ignore', over='ignore', divide='ignore', invalid='ignore')
np.seterr(use_inf_as_null=True)
```
这将忽略除以零的警告,将所有异常设置为无,将无穷值视为null。请注意,这可能会影响其他部分代码的行为,因此请谨慎使用。
相关问题
"No such keys(s): 'mode.use_inf_as_null'"
这个错误一般是出现在使用 TensorFlow 1.x 版本时,因为在 TensorFlow 2.x 中已经没有了 `mode.use_inf_as_null` 这个参数。
如果你想要在 TensorFlow 1.x 中使用 `mode.use_inf_as_null` 参数,可以尝试手动安装最新版本的 TensorFlow Probability,因为在最新版本的 TensorFlow Probability 中已经支持 `mode.use_inf_as_null` 参数了。
具体操作可以参考以下步骤:
1. 安装 TensorFlow Probability:
```
pip install tensorflow-probability
```
2. 导入 TensorFlow Probability 库并设置参数:
```python
import tensorflow_probability as tfp
tfd = tfp.distributions
# 设置参数
tfd.Normal(loc=0., scale=1., allow_nan_stats=False, name='Normal', validate_args=False, parameters={'mode': 'numeric', 'use_inf_as_null': False})
```
这样设置之后,`mode.use_inf_as_null` 参数就会被默认设置为 False,不会出现错误了。
OptionError: "No such keys(s): 'mode.use_inf_as_null'"
根据提供的引用内容,你遇到了一个OptionError,错误信息为"No such keys(s): 'mode.use_inf_as_null'"。这是因为你的pandas版本是2.0.2,而在这个版本中,mode.use_inf_as_null已经被弃用并且不存在了。相反,你需要使用mode.use_inf_as_na。如果你想使用mode.use_inf_as_null,你需要回退到1.5.2版本。你可以通过以下命令回退到1.5.2版本:
```shell
pip install pandas==1.5.2
```
请注意,回退到旧版本可能会导致其他问题,因此请谨慎操作。