4
Python版本:3.5.2 numpy的版本:1.12.1numpy的frombuffer - AttributeError的: '海峡' 对象有没有属性 '__buffer__'
错误:
import numpy as np
s = 'Hello World'
np.frombuffer(s, dtype='S1')
AttributeError: 'str' object has no attribute '__buffer__'
事情尝试:
- Tried Online Ideone compiler, got same error in Python3.xx.
- Referred scipy faqs for numpy and python compatible version, which states "NumPy support the Python 2.x series, (versions 2.6 and 2.7), as well as Python 3.2 and newer. The first release of NumPy to support Python 3 was NumPy 1.5.0."
不能找出问题,尝试相同的问题stackoverflow,但没有发现,可能是我错过了它。 关于为什么错误以及如何在python3.xx中解决它的任何建议或线索。
所以一开始我很喜欢哦..这是一个简单的Dtype错误。然后我试了一下,然后我更加努力地尝试。现在我有焦虑。 – Scheme
字符串不是缓冲区,特别是不在py3中,其中字符串是unicode。你想要什么阵列?你为什么使用'frombuffer'?这不是初学者的工具。 – hpaulj
'frombuffer' docs有这样一个例子,但是它需要为py3的使用进行改进。 – hpaulj