-1
我正在從以下格式的文本文件中讀取數據。通過添加新條目來寫入文本文件
1 1 5
1 3 3
1 5 4
2 1 5
2 4 3
3 1 2
3 3 4
3 4 3
3 5 4
第一列表示的coachId,第二列表示playerId,並且最後一列表示由每個教練給每個玩家給出的分數。所以現在說有3名教練和5名球員,我們提供的數據還不完整。我們基本上必須執行一個推薦系統,併爲每個教練產生每個球員缺少的得分。我已經完成了這部分。所以基本上現在我想生成一個輸出文件來填補缺失的分數。這是我的邏輯。
data = np.loadtxt('player.txt')
coaches = data.T[0]
players = data.T[1]
scores = data.T[2]
a = 0
total = 3 * 5 #total fields to fill is num of player times num of coaches
while a < total:
b = 0
while b < 3: #for each coach
#check if score was given
# if score is given don't do anything
# if score is not given get new socre and write it to file
我覺得這種方法可能需要很長時間,如果我很多教練和球員。有一個更好的方法嗎?
我懷疑你會先運行一個「GetAllMissingScores」類型的功能,那麼在那些分數分裝,比多得到更好的服務責任1一1循環。您如何設置了很可能會偏好(有可能是一種優化的解決方案,但我不是一個Python的傢伙) – Sitric
http://stackoverflow.com/questions/18689235/numpy-array-replace-nan-values-with - 平均值列 –
@Pardoido這有助於如何? – BlackJack