Netlogo 如何获取列表中每个项目的顺序(排名)?

Netlogo 如何获取列表中每个项目的顺序(排名)?,netlogo,Netlogo,例如,列表[5,1,6,7,9] 我要获取每个项目的顺序:[1 0 2 3 4] 这对于python来说很容易,但是如何在netlogo中做到这一点呢 p、 我正在赶作业。如果您知道解决方案,请尽快回复! 非常感谢 冒着为别人做家庭作业的风险,我将如何处理这件事。首先要意识到,如果我们对列表进行排序,结果列表的索引将是我们希望在最终输出中使用的“等级”。您可以使用从列表中获取数字的索引。然后,我们可以很容易地使用排序数组中的“秩”替换原始列表中的每个值 逐步示例: to step-by-step

例如,列表[5,1,6,7,9] 我要获取每个项目的顺序:[1 0 2 3 4] 这对于python来说很容易,但是如何在netlogo中做到这一点呢

p、 我正在赶作业。如果您知道解决方案,请尽快回复!
非常感谢

冒着为别人做家庭作业的风险,我将如何处理这件事。首先要意识到,如果我们对列表进行排序,结果列表的索引将是我们希望在最终输出中使用的“等级”。您可以使用从列表中获取数字的索引。然后,我们可以很容易地使用排序数组中的“秩”替换原始列表中的每个值

逐步示例:

to step-by-step-ranking
  let items [5 1 6 7 9]
  let sorted sort items 
  ; sorted is now [1 5 6 7 9]
  show sorted

  ; so the `position` of the number 5 in `sorted` is index `1`
  show position 5 sorted 
  ; and the `position` of the number 5 in `sorted` is index `0`
  show position 1 sorted
  ; and so on for the other items, `position` gives our rank

  ; so we just need to do `position n sorted` for each number in order
  ; which is what `map` will do for us
  ; `map` to `position` from `sorted` for each number in `items`
  let ranked map [ n -> position n sorted ] items   
  show ranked ; outputs [1 0 2 3 4]
end
如果你想要一个更通用的记者,你可以在任何数字列表上使用:

to-report rank [items]
  let sorted sort items
  let ranked map [ n -> position n sorted ] items
  report ranked
end

to test-rank
  show rank [5 1 6 7 9] ; outputs [1 0 2 3 4]
  show rank [ 10 9 3 2 10 9 3 2 11 ] ; outputs [6 4 2 0 6 4 2 0 8]
end

不容易-这不是我能想象的任何人想在NetLogo中做的事情。你确定你正确地解释了这个问题吗?将实际排序与使用
position
迭代查找每个元素相结合可能会奏效。您尝试了什么?当你试图自己解决这个问题时,你到底在哪里陷入困境?欢迎来到SO;请看一下线程(tl;dr:从不)。