排序@排序和排名排列
正如 nazdrovje 所指出的(参见此处)Ordering@Ordering
可用于获取列表中每个元素的排名。即使列表包含重复元素,结果也是一个 n 排列(视为整数 1 到 n 的有序列表,无重复),其中排名最低的元素分配为 1,第二低的元素分配为 2,正如 Andrzej Kozlowski 所指出的,以下内容成立(另请参阅此处):
(Sort@mylist)[[Ordering@Ordering@mylist]]==mylist
我愿意产生一个排名排列,其中最高排名元素被分配1,第二最高 2等,这样以下内容成立:
(Reverse@Sort@mylist)[[newPermutation]]==mylist
这看起来很简单,但我只是能够想出一个相当尴尬的解决方案。目前我正在执行以下操作:
newPermutation= Ordering@Ordering[Ordering@Ordering@mylist,All,Greater]
是否有更优雅或更直观的方法?肯定有吗?
示例:
mylist= {\[Pi],"abc",40,1, 300, 3.2,1};
Ordering@Ordering@mylist
Ordering@Ordering[Ordering@Ordering@mylist,All,Greater]
输出(注意排列之间的倒数关系)
{7,6,4,1,5,3,2}
{1,2,4,7,3,5,6}
(以下两者均计算为 True)
Sort@mylist)[[Ordering@Ordering@mylist]]== mylist
Reverse@Sort@mylist)[[ Ordering@Ordering[Ordering@Ordering@mylist,All,Greater]]]== mylist
As pointed out by nazdrovje (see here) Ordering@Ordering
may be used to obtain the rank of each element in a list. Even when the list contains repeated elements the result is an n-permutation (taken as an ordered list of integers 1 to n without repetition), where the lowest ranked element is assigned 1, the second lowest 2, etc. As pointed out by Andrzej Kozlowski, the following holds (see also here):
(Sort@mylist)[[Ordering@Ordering@mylist]]==mylist
I'd like to produce a ranking permutation where the highest ranked element is assigned 1, the second highest 2, etc. such that the following holds:
(Reverse@Sort@mylist)[[newPermutation]]==mylist
This seems simple, but I have only been able to come up with quite an awkward solution. At the moment I do the following:
newPermutation= Ordering@Ordering[Ordering@Ordering@mylist,All,Greater]
Is there a more elegant,or more intuitive, way? There surely must be?
An example:
mylist= {\[Pi],"abc",40,1, 300, 3.2,1};
Ordering@Ordering@mylist
Ordering@Ordering[Ordering@Ordering@mylist,All,Greater]
Output (note the reciprocal relationship between the permutations)
{7,6,4,1,5,3,2}
{1,2,4,7,3,5,6}
(Both the following evaluate to True)
Sort@mylist)[[Ordering@Ordering@mylist]]== mylist
Reverse@Sort@mylist)[[ Ordering@Ordering[Ordering@Ordering@mylist,All,Greater]]]== mylist
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你设置
然后
是
如果
True
所以,你可以定义
比如
is
True
If you set
then
and
is
True
So, you may define
Such as
is
True