numpy数据类型的最大允许值 [英] Maximum allowed value for a numpy data type

查看:955
本文介绍了numpy数据类型的最大允许值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一系列数据类型(uint8,uint16,int16等)的numpy数组.我希望能够检查是否可以在给定数据类型的数组范围内表示数字.我正在想象看起来像这样的东西:

I am working with numpy arrays of a range of data types (uint8, uint16, int16, etc.). I would like to be able to check whether a number can be represented within the limits of an array for a given datatype. I am imagining something that looks like:

>>> im.dtype
dtype('uint16')
>>> dtype_max(im.dtype)
65535
>>> dtype_min(im.dtype)
0

是否存在类似的东西?顺便说一句,我觉得以前必须问这个问题,但是我的搜索空了,所有类似问题"似乎都不相关.

Does something like this exist? By the way, I feel like this has to have been asked before, but my search came up empty, and all of the "similar questions" appear to be unrelated.

当然,既然我已经问过,那么相关"问题之一确实具有答案.哎呀.

Of course, now that I've asked, one of the "related" questions does have the answer. Oops.

推荐答案

min_value = np.iinfo(im.dtype).min
max_value = np.iinfo(im.dtype).max

docs:

docs:

这篇关于numpy数据类型的最大允许值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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