如何检查python中的float的大小? [英] How to check the size of a float in python?
问题描述
我想检查浮点数实际上是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屋!