脾气暴躁:最大值是NaN [英] Numpy: Maximal Value is NaN

查看:90
本文介绍了脾气暴躁:最大值是NaN的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我关于Python的问题确实微不足道:我需要修改什么功能max()为任何编译器返回真实值?

My question about Python is really trivial: What do I have to modify that the function max() returns a real value for any compiler?

import numpy as np
a = np.array([-1, 0, 1, np.nan])
# The maximal value is 1. It is not nan!
a.max()

可以使用以下代码,但对我来说看起来很丑:

There is the possibility to use the following code but it looks ugly to me:

a[np.logical_not(np.isnan(a))].max()

推荐答案

@Divakar使用

As was answered by @Divakar using np.nanmax(a) will solve your question.

这篇关于脾气暴躁:最大值是NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆