One - One Code All

Blog Content

RuntimeWarning: invalid value encountered in true_divide

Python 统计学-科学计算   2015-03-03 19:41:03

RuntimeWarning: invalid value encountered in true_divide


Add the following before this line:


numpy.seterr(divide='ignore', invalid='ignore')

或者是:RuntimeWarning: invalid value encountered in divide


import numpy as np

olderr = np.seterr(all='ignore')

==========================


You may have a NAN, INF, or NINF floating around somewhere. Try this:


np.isfinite(diff_images).all()

np.isfinite(b_0).all()


If one or both of those returns False, that's likely the cause of the runtime error.

==================

解决:

这样:

python -W ignore::RuntimeWarning my_script.py

或者这样:

import warnings

warnings.filterwarnings("ignore")



上一篇:numpy逻辑函数np.logical_and/or/not (逻辑与/或/非)
下一篇:pandas缺失值与空值处理,df.fillna()以上一个值向下填充ffill

The minute you think of giving up, think of the reason why you held on so long.