Forgot password
 Register account
View 254|Reply 1

关于SortBy的疑问

[Copy link]

3211

Threads

7832

Posts

52

Reputation

Show all posts

hbghlyj posted 2023-4-3 13:31 |Read mode
SortBy[{1,4,2,3},{EvenQ}]
{1,3,4,2}

SortBy[{1,4,2,3},EvenQ]
{1,3,2,4}

为何不一样?

3211

Threads

7832

Posts

52

Reputation

Show all posts

original poster hbghlyj posted 2023-4-5 16:28
好像是因为, SortBy会把结果用默认排序, 导致这里的{1,3,4,2}变成{1,3,2,4}
如果加{}, 表示依次用这组函数来排序, 规定了就是这组, 完了就不会再用默认排序
Wolfram Language Documentation
If some of the $f[e_i]$ are the same, then the canonical order of the corresponding $e_i$ is used.

Quick Reply

Advanced Mode
B Color Image Link Quote Code Smilies
You have to log in before you can reply Login | Register account

$\LaTeX$ formula tutorial

Mobile version

2025-7-20 05:59 GMT+8

Powered by Discuz!

Processed in 0.011854 seconds, 22 queries