如何检查python中的float的大小? [英] How to check the size of a float in python?

查看:892
本文介绍了如何检查python中的float的大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查浮点数实际上是32位还是64位(以及numpy浮点数组的位数).应该有一个内置的,但只是没有发现...

I want to check whether a float is actually 32 or 64bits (and the number of bits of a numpy float array). There should be a built-in, but just didn't find out...

推荐答案

Python float的属性可以通过 sys.float_info .它返回诸如最大/最小值,最大/最小exp值等信息.这些属性可以潜在地用于计算浮点数的字节大小.但是,在许多不同的体系结构上,除了64位以外,我再也没有遇到过.

Properties of a Python float can be requested via sys.float_info. It returns information such as max/min value, max/min exp value, etc. These properties can potentially be used to calculate the byte size of a float. I never encountered anything else than 64 bit, though, on many different architectures.

NumPy数组的项目大小可能有所不同,但是您可以按a.itemsize来检查其大小(以字节为单位),其中a是NumPy数组.

The items of a NumPy array might have different size, but you can check their size in bytes by a.itemsize, where a is a NumPy array.

这篇关于如何检查python中的float的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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