python – 为数组中的nan和inf值创建一个掩码

python – 为数组中的nan和inf值创建一个掩码,第1张

概述我必须从两个数组中删除nan和inf值. 我发现这个帖子对于去除nan有用 https://stackoverflow.com/a/48591908/7541421.当我可以创建一个掩码去除nan和inf值时,有没有类似的解决方案? 下面的例子只是说明性的,我有大尺寸的数组(400个元素) import numpy as npfrom numpy import nan, infa = np. 我必须从两个数组中删除nan和inf值.
我发现这个帖子对于去除nan有用 https://stackoverflow.com/a/48591908/7541421.当我可以创建一个掩码去除nan和inf值时,有没有类似的解决方案?

下面的例子只是说明性的,我有大尺寸的数组(400个元素)

import numpy as npfrom numpy import nan,infa = np.asarray([0.5,6.2,np.nan,4.5,np.inf])b = np.asarray([np.inf,np.inf,0.3,0.5])bad = ~np.logical_or(np.isnan(a),np.isnan(b))X = np.compress(bad,a)  Y = np.compress(bad,b) BIAS = np.nanmean(X - Y)RMSE = np.sqrt(np.nanmean((X - Y)**2))CORR = np.corrcoef(X,Y)

我需要这个,以便正确地获得统计数据和图表

解决方法 np.isfinite

Test element-wise for finiteness (not infinity or not Not a Number).

总结

以上是内存溢出为你收集整理的python – 为数组中的nan和inf值创建一个掩码全部内容,希望文章能够帮你解决python – 为数组中的nan和inf值创建一个掩码所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1194366.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-03
下一篇 2022-06-03

发表评论

登录后才能评论

评论列表(0条)

保存