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