オブジェクトのグループを反復処理して、最も効率的な方法でそれらの平均を見つけるにはどうすればよいですか?これは1つのループだけを使用します(おそらくNumpyのループを除く)が、もっと良い方法があるかどうか疑問に思いました。現在、私はこれを行っています:
scores = []
ratings= []
negative_scores = []
positive_scores = []
for t in text_collection:
scores.append(t.score)
ratings.append(t.rating)
if t.score < 0:
negative_scores.append(t.score)
elif t.score > 0:
positive_scores.append(t.score)
print "average score:", numpy.mean(scores)
print "average rating:", numpy.mean(ratings)
print "average negative score:", numpy.mean(negative_scores)
print "average positive score:", numpy.mean(positive_scores)
これを行うためのより良い方法はありますか?