2017-04-14 69 views
0

我正在嘗試將數據文件讀取到包含浮點數和字符串的數組中。如何向數組中讀取數據而不使用''

metadata = genfromtxt('iris_labels.tsv',delimiter='\t', dtype=str) print(metadata)

這給我output

是可以忽略的( '')簽署?

+0

如果需要,可以使用int()或float()將字符串轉換爲整數或浮點數。 –

+0

你的意思是你想忽略單引號? – Nurjan

+0

@Nurzhan是的,那就是我的意思。 – JefferyLR

回答

1

不是numpy的專家,我還沒有嘗試過了,但我認爲你正在尋找的東西像

my_dtype=np.dtype([ 
    ('petal.w', np.float), 
    ('petal.h', np.float), 
    ('sepal.w', np.float), 
    ('sepal.h', np.float), 
    ('species', 'a32') 
    ]) 

附:我不知道列的實際順序

+0

這究竟是什麼? – JefferyLR

+0

'genfromtxt'有'dtype'參數; numpy dtype是對某些數據結構的描述。如果你要求將數據作爲字符串加載,那就是你將要得到的。您必須找到如何將第一列轉換爲浮動 –

相關問題