【发布时间】:2014-04-04 21:09:14
【问题描述】:
我需要能够基于单个列对数组进行排名,然后再次使用第二列作为基本的决胜局,然后将这两个排名保存到数据库中
数组:
array = np.array(
[(70,3,100),
(72,3,101),
(70,2,102)], dtype=[
('score','int8'),
('tiebreaker','int8'),
('row_id','int8')])
array['score'] = array([70, 72, 70], dtype=int8)
仅使用“分数”列的第一排名将返回
(1,3,1)
然后使用'score'和'tiebreaker'列的第二个Rank排名
(2,3,1)
然后我想将这两个等级保存到数据库中,例如:
result1 = Result.objects.get(id=array[0]['row_id'])
result1.relative_rank = 1
result1.absolute_rank = 2
results.save()
【问题讨论】:
-
array.sort(order=['score', 'tiebreaker'])
标签: python arrays django numpy scipy