我有我有三列讀取一個文件,該文件是這樣的:連接三個numpy的陣列,並將它們寫入文件
01 29 54.288
01 48 23.384
01 56 42.495
.. .. ......
我需要這三個數字,做一些數學與第三列舍其關閉,以一個整數,然後將它們寫入到一個新的文件,使他們看起來像這樣:
01295
01482
01564
簡化代碼:
import numpy as np
data = np.loadtxt(filename,dtype=str)
ra1 = data[:,1]
ra2 = data[:,2]
ra3 = data[:,3]
# This part is because ra3 is in arcseconds, it's correct, just here for reference
ra3 = ra3.astype(float)
ra3n = ra3/60 * 10
ra3n = np.rint(ra3n)
ra = ra1+ra2+ra3n
print ra
產生了錯誤:
unsupported operand type(s) for +: 'numpy.ndarray' and 'numpy.ndarray'
我也試圖利用np.concatenate
,但是這似乎並沒有做我想做的,除非我使用它錯了。任何建議將不勝感激。
看看np.hstack()。 http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.hstack.html –