numpy.getbuffer导致AttributeError:'模块'对象没有属性'getbuffer' [英] numpy.getbuffer causes AttributeError: 'module' object has no attribute 'getbuffer'

查看:446
本文介绍了numpy.getbuffer导致AttributeError:'模块'对象没有属性'getbuffer'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从Python 3中的一个numpy数组中获取一个缓冲区. 我发现以下代码:

I want to get a buffer from a numpy array in Python 3. I have found the following code:

$ python3
Python 3.2.3 (default, Sep 25 2013, 18:25:56) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
>>> a = numpy.arange(10)
>>> numpy.getbuffer(a)

但是在最后一步会产生错误:

However it produces the error on the last step:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute 'getbuffer'

我为什么做错了? 该代码对Python 2正常工作. 我正在使用的numpy版本是1.6.1.

Why am I doing wrong? The code works fine for Python 2. The numpy version I'm using is 1.6.1.

推荐答案

根据

PyBuffer(对象)

PyBuffer (object)

由于Py3中有一个本机缓冲区对象,因此memoryview 从Py3的多数组中删除了newbuffer getbuffer函数: 它们的功能由新的memoryview对象接管.

Since there is a native buffer object in Py3, the memoryview, the newbuffer and getbuffer functions are removed from multiarray in Py3: their functionality is taken over by the new memoryview object.

>>> import numpy
>>> a = numpy.arange(10)
>>> memoryview(a)
<memory at 0xb60ae094>
>>> m = _
>>> m[0] = 9
>>> a
array([9, 1, 2, 3, 4, 5, 6, 7, 8, 9])

这篇关于numpy.getbuffer导致AttributeError:'模块'对象没有属性'getbuffer'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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