我正在學習numpy中genfromtxt的I/O函數。 我試過numpy的用戶指南中的一個例子。它是關於genfromtxt的註釋參數。numpy中genfromtxt的註釋參數
下面是從numpy的的用戶指南的例子:
>>> data = """#
... # Skip me !
... # Skip me too !
... 1, 2
... 3, 4
... 5, 6 #This is the third line of the data
... 7, 8
... # And here comes the last line
... 9, 0
... """
>>> np.genfromtxt(StringIO(data), comments="#", delimiter=",")
[[ 1. 2.]
[ 3. 4.]
[ 5. 6.]
[ 7. 8.]
[ 9. 0.]]
下面我嘗試:
結果出來:
genfromtxt:空輸入文件:「<在0x0000020555DC5EB8 _io.BytesIO對象>」 warnings.warn( 'genfromtxt:空輸入文件: 「%S」' %FNAME)
我知道問題是與數據。任何人都可以教我如何設置示例中顯示的數據? 非常感謝。
爲第一個genfromtxt參數嘗試使用StringIO而不是BytesIO – Jonas
爲什麼要在數據中插入反斜槓? – BrenBarn