我有一個CVS文件,其中有數字的三列高達每三個數字:閱讀文件作爲陣列
1 0 0
2 0 0
3 0 0
4 0 0
5 0 0
6 0 0
7 0 0
8 0 0
9 0 0
10 0 0
11 0 0
我想分別讀取列,並能夠利用它們作爲使用數組:
data = np.loadtxt('file.csv')
x = data[:, 0]
y = data[:, 1]
但我發現了:
X = np.array(X, dtype)
ValueError: setting an array element with a sequence.
相反,如果我使用的線路x,y = np.loadtxt('Beamprofile.txt', usecols=(0,1), unpack=True)
錯誤消失,但x和y在進一步的操作中似乎沒有被正確讀取。
可能的重複[從python讀取csv文件](http://stackoverflow.com/questions/14725020/read-csv-file-from-python) – gsamaras
這是一個numpy特定的文件讀取isue。 – hpaulj
顯示'data'的形狀和dtype。甚至可以打印幾行數據或文件。 – hpaulj