如何获取有效的Numpy数据类型范围? [英] How to get the range of valid Numpy data types?

查看:84
本文介绍了如何获取有效的Numpy数据类型范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有兴趣寻找一种特定的Numpy类型(例如np.int64np.uint32np.float32等),所有可能有效值的范围是多少(例如np.int32最多可以存储数字) 2**31-1).当然,我想从理论上讲每种类型都可以解决这个问题,但是有没有一种方法可以在运行时执行此操作以确保更多的可移植代码?

I'm interested in finding for a particular Numpy type (e.g. np.int64, np.uint32, np.float32, etc.) what the range of all possible valid values is (e.g. np.int32 can store numbers up to 2**31-1). Of course, I guess one can theoretically figure this out for each type, but is there a way to do this at run time to ensure more portable code?

推荐答案

从一些讨论列表中引用:

Quoting from a numpy discussion list:

That information is available via numpy.finfo() and numpy.iinfo():

In [12]: finfo('d').max
Out[12]: 1.7976931348623157e+308

In [13]: iinfo('i').max
Out[13]: 2147483647

In [14]: iinfo('uint8').max
Out[14]: 255

链接此处.

这篇关于如何获取有效的Numpy数据类型范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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