それを使用すると機能しnumpy.loadtxt
、converters
パラメーターを使用して関数を定義できます。次のtmp.txt
ファイルを持っている:
11,12,13,14,15,16,17,18,19
21,22,23,24,25,26,27,28,29
31,32,33,34,35,36,37,38,39
41,42,43,44,45,46,47,48,49
51,52,53,54,55,56,57,58,59
選択した列を次のようにロードできます (スタックする順序も選択します)。
import numpy as np
print np.loadtxt('tmp.txt',delimiter=',',usecols=(-2,-1))
#[[ 18. 19.]
# [ 28. 29.]
# [ 38. 39.]
# [ 48. 49.]
# [ 58. 59.]]
print np.loadtxt('tmp.txt',delimiter=',',usecols=(-1,-2),converters={-1: lambda x: float(x)+100})
#[[ 119. 18.]
# [ 129. 28.]
# [ 139. 38.]
# [ 149. 48.]
# [ 159. 58.]]