numpy.getbuffer causes AttributeError: 'module' object has no attribute 'getbuffer'
numpy, python, python-3.x
Solution
According to Developer notes on the transition to Python 3:
PyBuffer (object)
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])
Problem
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' ``` Why am I doing wrong? The code works fine for Python 2. The numpy version I'm using is 1.6.1.