【发布时间】:2021-07-13 04:28:07
【问题描述】:
我使用的是 Julia 1.6.1。
B 是一个矩阵。例如,
B =
[ 2 4 4 4 5 ;
1 2 2 3 5 ;
1 2 3 3 3 ;
1 2 2 5 6 ;
1 3 4 4 4 ; ]
我想对每一行进行强制排序。
sortedB = sortslices( B, dims=1, rev=true)
然后,我们得到排序 B
sortedB =
[ 2 4 4 4 5 ; # 1st row of the original matrix B
1 3 4 4 4 ; # 5th row of the original matrix B
1 2 3 3 3 ; # 3rd row of the original matrix B
1 2 2 5 6 ; # 4th row of the original matrix B
1 2 2 3 5 ;] # 2nd row of the original matrix B
我想得到数组[1 5 3 4 2]。
我该怎么做?
sortperm 好像不行。
sortperm( sortslices( B, dims=1, rev=true) )
# ERROR: MethodError; no method matching sortperm(::Matrix{Int64})
【问题讨论】: