无法在64位架构上的Python中使用128位浮点 [英] Cannot use 128bit float in Python on 64bit architecture

查看:338
本文介绍了无法在64位架构上的Python中使用128位浮点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在python终端中检查了指针的大小(在Enthought Canopy IDE中) 通过

I checked the size of a pointer in my python terminal (in Enthought Canopy IDE) via

import ctypes
print (ctypes.sizeof(ctypes.c_voidp) * 8)

我具有64位体系结构,并且使用numpy.float64很好.但是我不能使用np.float128?

I've a 64bit architecture and working with numpy.float64 is just fine. But I cannot use np.float128?

np.array([1,1,1],dtype=np.float128)

np.float128(1)

导致:

AttributeError: 'module' object has no attribute 'float128'

我正在运行以下版本:

sys.version_info(major=2, minor=7, micro=6, releaselevel='final', serial=0)

推荐答案

更新:从注释来看,在64位系统上甚至具有128位浮点数似乎也没有意义.

Update: From the comments, it seems pointless to even have a 128 bit float on a 64 bit system.

我在具有以下功能的64位Ubuntu 14.04系统上使用anaconda sys.version_info(major=2, minor=7, micro=9, releaselevel='final', serial=0)

I am using anaconda on a 64-bit Ubuntu 14.04 system with sys.version_info(major=2, minor=7, micro=9, releaselevel='final', serial=0)

和128位浮点数可以正常工作:

and 128 bit floats work fine:

import numpy
a = numpy.float128(3)

这可能是发行问题.试试:

This might be an distribution problem. Try:

  • Install Anaconda
  • Update canopy
  • Check that the version of python in the path is the one supplied by anaconda or canopy

从评论中更新:

不是我的不赞成,但是这篇文章并没有真正回答为什么不 np.float128存在于我的计算机上"隐含的问题.真正的答案是 这是特定于平台的:float128在某些平台上存在,但 不是其他人,而在确实存在的那些平台上,几乎 当然是80位x87扩展精度类型,填充为128 位. –马克·迪金森

Not my downvote, but this post doesn't really answer the "why doesn't np.float128 exist on my machine" implied question. The true answer is that this is platform specific: float128 exists on some platforms but not others, and on those platforms where it does exist it's almost certainly simply the 80-bit x87 extended precision type, padded to 128 bits. – Mark Dickinson

这篇关于无法在64位架构上的Python中使用128位浮点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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