# \#sortperm

**URL:** https://discourse.julialang.org/tag/sortperm/150.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Find n smallest values in an n dims array](https://discourse.julialang.org/t/find-n-smallest-values-in-an-n-dims-array/81092)

<div class="topic-metadata">

**Author:** [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Replies:** 22\
**Last updated:** [February 13, 2026, 2:07pm UTC](https://discourse.julialang.org/t/find-n-smallest-values-in-an-n-dims-array/81092 "2026-02-13T14:07:33Z")

</div>

Hi Every one! I have the bad tendency of working with N dims arrays. Right now I have a 10x20x6 arrays and I need to find the index of the 5 smallest values. I have tried PartialQuickSort and argmin but I can’t get the…

---

## [Is any implementation of sortperm running on multiple threads available?](https://discourse.julialang.org/t/is-any-implementation-of-sortperm-running-on-multiple-threads-available/111853)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 3\
**Last updated:** [February 4, 2026, 2:41pm UTC](https://discourse.julialang.org/t/is-any-implementation-of-sortperm-running-on-multiple-threads-available/111853 "2026-02-04T14:41:03Z")

</div>

As it says: Even experimental code would help. Thanks! Edit: Found this great piece of code: Parallel quicksort openmp - #18 by pitsianis I sort of remembered having seen it, but could not find it again.

---

## [How to sort a column of cell arrays, using the same criteria as my table?](https://discourse.julialang.org/t/how-to-sort-a-column-of-cell-arrays-using-the-same-criteria-as-my-table/130278)

<div class="topic-metadata">

**Author:** [@Leon6](https://discourse.julialang.org/u/Leon6)\
**Replies:** 6\
**Last updated:** [June 27, 2025, 4:28pm UTC](https://discourse.julialang.org/t/how-to-sort-a-column-of-cell-arrays-using-the-same-criteria-as-my-table/130278 "2025-06-27T16:28:54Z")

</div>

I have a table T1 with 1000 rows and 20 columns. I also have a column based cell array B with the size of 1000 x 1. Here is my code to sort the table: T1 = T1\[sortperm(T1\[:, 12\]; rev=true), :\]; # Sort by the depth val…

---

## [10x faster sortperm()](https://discourse.julialang.org/t/10x-faster-sortperm/93026)

<div class="topic-metadata">

**Author:** [@LSchwerdt](https://discourse.julialang.org/u/LSchwerdt)\
**Replies:** 10\
**Last updated:** [October 29, 2024, 8:59pm UTC](https://discourse.julialang.org/t/10x-faster-sortperm/93026 "2024-10-29T20:59:31Z")

</div>

Motivated by LilithHafner s work to add radix sorting to Julia 1.9 and the resulting performance improvements of sort(), I did some tests to see if sortperm() could be sped up as well. To test this, I implemented diffe…

---

## [Why does sortperm! allocate here?](https://discourse.julialang.org/t/why-does-sortperm-allocate-here/112028)

<div class="topic-metadata">

**Author:** [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Replies:** 4\
**Last updated:** [March 24, 2024, 1:47pm UTC](https://discourse.julialang.org/t/why-does-sortperm-allocate-here/112028 "2024-03-24T13:47:39Z")

</div>

Hello! I think I am missing something really simple, I just don’t get why allocations occur, when I have preallocated index array. function main() Cartesians = Vector{CartesianIndex{2}}(undef, 100) SortedInd…

---

## [Why aren't the permutations from sortslices() available?](https://discourse.julialang.org/t/why-arent-the-permutations-from-sortslices-available/99029)

<div class="topic-metadata">

**Author:** [@g2g](https://discourse.julialang.org/u/g2g)\
**Replies:** 1\
**Last updated:** [March 16, 2024, 6:30pm UTC](https://discourse.julialang.org/t/why-arent-the-permutations-from-sortslices-available/99029 "2024-03-16T18:30:05Z")

</div>

I’m writing some data comparison code and it would be helpful if Julia had a sortslicesperm() similar to sortperm() so that a matrix could be sorted (like a vector) by M = rand(0:2, 16, 4); p = sortslicesperm(M, dims=1)…

---

## [Find permutation of an array such that it is equal to another array](https://discourse.julialang.org/t/find-permutation-of-an-array-such-that-it-is-equal-to-another-array/85365)

<div class="topic-metadata">

**Author:** [@heindelj](https://discourse.julialang.org/u/heindelj)\
**Replies:** 10\
**Last updated:** [May 31, 2023, 8:08pm UTC](https://discourse.julialang.org/t/find-permutation-of-an-array-such-that-it-is-equal-to-another-array/85365 "2023-05-31T20:08:36Z")

</div>

I have a rather simple question that I’m surprised I haven’t been able to figure out easily. Suppose I have two arrays, A=\["A","C","B","C"\], and B=\["C","B","A","C"\]. Treat A as the correct sorted order of the array. Ho…

---

## [Eigen values and vectors sorting](https://discourse.julialang.org/t/eigen-values-and-vectors-sorting/98637)

<div class="topic-metadata">

**Author:** [@papar](https://discourse.julialang.org/u/papar)\
**Replies:** 7\
**Last updated:** [May 10, 2023, 11:33pm UTC](https://discourse.julialang.org/t/eigen-values-and-vectors-sorting/98637 "2023-05-10T23:33:41Z")

</div>

I am trying to work out how to sort eigen values and eigen vectors that are consistent with other languages. I use the following code on a covariance matrix: eigen\_vals, eigen\_vector = eigen(covariance\_matrix) This gi…

---

## [What is Julia's maxk(Matlab) that returns the indice of top K largest values?](https://discourse.julialang.org/t/what-is-julias-maxk-matlab-that-returns-the-indice-of-top-k-largest-values/14100)

<div class="topic-metadata">

**Author:** [@complexfilter](https://discourse.julialang.org/u/complexfilter)\
**Replies:** 20\
**Last updated:** [May 9, 2023, 4:19pm UTC](https://discourse.julialang.org/t/what-is-julias-maxk-matlab-that-returns-the-indice-of-top-k-largest-values/14100 "2023-05-09T16:19:51Z")

</div>

I am currently converting my Matlab code into Julia code. In an effort to converting the Matlab off-the-shelf function maxk, which returns the values and indices of the top K largest/smallest values, I found it difficult…

---

## [Parallel quicksort openmp](https://discourse.julialang.org/t/parallel-quicksort-openmp/88499)

<div class="topic-metadata">

**Author:** [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Replies:** 30\
**Last updated:** [March 24, 2023, 8:26pm UTC](https://discourse.julialang.org/t/parallel-quicksort-openmp/88499 "2023-03-24T20:26:47Z")

</div>

Hi, I was wondering how it is possible to parallelise a quicksort algorithm below (from rosetta code) in Julia? In c with openmp one would use #pragma omp task. Example : But what is the equivalent in Julia? Thank …

---

## [Performance tips for a function which finds n maximums in a matrix](https://discourse.julialang.org/t/performance-tips-for-a-function-which-finds-n-maximums-in-a-matrix/96425)

<div class="topic-metadata">

**Author:** [@eduardosalaz](https://discourse.julialang.org/u/eduardosalaz)\
**Replies:** 8\
**Last updated:** [March 23, 2023, 5:49am UTC](https://discourse.julialang.org/t/performance-tips-for-a-function-which-finds-n-maximums-in-a-matrix/96425 "2023-03-23T05:49:13Z")

</div>

Hi everyone, I have been trying to squeeze out as much performance as possible out from the following function, which finds the n largest (or maximum) values of a matrix and returns those values and their positions in t…

---

## [In-place inverse permutation](https://discourse.julialang.org/t/in-place-inverse-permutation/94368)

<div class="topic-metadata">

**Author:** [@jacob-roth](https://discourse.julialang.org/u/jacob-roth)\
**Replies:** 1\
**Last updated:** [February 9, 2023, 6:16pm UTC](https://discourse.julialang.org/t/in-place-inverse-permutation/94368 "2023-02-09T18:16:46Z")

</div>

Is there a reason that there is not an in-place equivalent of sortperm!, i.e., “invperm!”? One current (v1.8.3) approach would be to call invpermute!(v, sig) for permutation sig, but the docs say that for v with many el…

---

## [Can't get sortperm to return the sorting order of columns of a matrix](https://discourse.julialang.org/t/cant-get-sortperm-to-return-the-sorting-order-of-columns-of-a-matrix/84081)

<div class="topic-metadata">

**Author:** [@Gus\_Hart](https://discourse.julialang.org/u/Gus_Hart)\
**Replies:** 11\
**Last updated:** [July 16, 2022, 11:27am UTC](https://discourse.julialang.org/t/cant-get-sortperm-to-return-the-sorting-order-of-columns-of-a-matrix/84081 "2022-07-16T11:27:38Z")

</div>

I’m sorting the columns of each matrix in long vector of matrices (having the matrix columns in a canonical order makes it easy to identify approximately equal matrices). Here’s a minimal working example: julia\> t 3×2 t…

---

## [Returning the n lowest values across columns in a dataframe](https://discourse.julialang.org/t/returning-the-n-lowest-values-across-columns-in-a-dataframe/81954)

<div class="topic-metadata">

**Author:** [@Snowy](https://discourse.julialang.org/u/Snowy)\
**Replies:** 7\
**Last updated:** [June 1, 2022, 5:37am UTC](https://discourse.julialang.org/t/returning-the-n-lowest-values-across-columns-in-a-dataframe/81954 "2022-06-01T05:37:28Z")

</div>

Hi all, My first post was removed (not sure why), so here is try number 2… I’m new to Julia and am stuck on a problem. I have a dataframe defined as follows: df = DataFrame((name=\["S1","S2","S3","S4","S5"\],Z1=\[41,12,…

---

## [Faster Alternatives to sortperm](https://discourse.julialang.org/t/faster-alternatives-to-sortperm/80170)

<div class="topic-metadata">

**Author:** [@Josa9321](https://discourse.julialang.org/u/Josa9321)\
**Replies:** 9\
**Last updated:** [May 10, 2022, 4:33pm UTC](https://discourse.julialang.org/t/faster-alternatives-to-sortperm/80170 "2022-05-10T16:33:18Z")

</div>

Hi, I am manipulating an matrix (one or more lines) that has the priority numbers of another one, for example: priority = \[0.1 0.9 0.4 0.7 0.3\] # matrix filled using rand() A = \[col1 col2 col3 col4 col5\] # matrix fille…

---

## [What is our equivalent of numpy.argpartition?](https://discourse.julialang.org/t/what-is-our-equivalent-of-numpy-argpartition/75626)

<div class="topic-metadata">

**Author:** [@rakeshvar](https://discourse.julialang.org/u/rakeshvar)\
**Replies:** 1\
**Last updated:** [February 2, 2022, 7:32am UTC](https://discourse.julialang.org/t/what-is-our-equivalent-of-numpy-argpartition/75626 "2022-02-02T07:32:27Z")

</div>

What is the julia equivalent of numpy’s argpartition? Here is how it works: Let’s say you want to get the indices of the top five entries of an array. As an example, say I have probabilites of n events stored in an ar…

---

## [Cant find order](https://discourse.julialang.org/t/cant-find-order/73637)

<div class="topic-metadata">

**Author:** [@JackStrauss](https://discourse.julialang.org/u/JackStrauss)\
**Replies:** 2\
**Last updated:** [December 26, 2021, 8:51am UTC](https://discourse.julialang.org/t/cant-find-order/73637 "2021-12-26T08:51:06Z")

</div>

Hello everybody Julia has order() which seems to be used for sorting dataframes. But my search skills have failed me in finding a function that gives me the order of elements in a vector. Like order(\[10.2,-3,5\]) give…

---

## [Use of \`Perm\` to find sorted subset of indices?](https://discourse.julialang.org/t/use-of-perm-to-find-sorted-subset-of-indices/70912)

<div class="topic-metadata">

**Author:** [@mehdi](https://discourse.julialang.org/u/mehdi)\
**Replies:** 7\
**Last updated:** [November 5, 2021, 7:07pm UTC](https://discourse.julialang.org/t/use-of-perm-to-find-sorted-subset-of-indices/70912 "2021-11-05T19:07:00Z")

</div>

I want to use sortperm on only a subset of indices of an array a, I couldn’t find how to do it with the sortperm function, I can simply use sort on the subset of indices s\_subs this way: sort(s\_subs, by = x -\> a\[x\]) It…

---

## [Performance difference in permuting Arrays](https://discourse.julialang.org/t/performance-difference-in-permuting-arrays/69425)

<div class="topic-metadata">

**Author:** [@mrVeng](https://discourse.julialang.org/u/mrVeng)\
**Replies:** 4\
**Last updated:** [October 11, 2021, 1:23pm UTC](https://discourse.julialang.org/t/performance-difference-in-permuting-arrays/69425 "2021-10-11T13:23:04Z")

</div>

Hi guys, I am trying to permute/shuffle a Vector of Vectors given a certain index. Some vectors can occur several times, so I need a buffer container for no allocations. MWE: vals = \[ \[1, 2, 3\], \[4, 5, 6\], \[7, 8, 9\] \] …

---

## [Sort an array according other array](https://discourse.julialang.org/t/sort-an-array-according-other-array/68295)

<div class="topic-metadata">

**Author:** [@maoc](https://discourse.julialang.org/u/maoc)\
**Replies:** 6\
**Last updated:** [September 17, 2021, 10:13am UTC](https://discourse.julialang.org/t/sort-an-array-according-other-array/68295 "2021-09-17T10:13:06Z")

</div>

I am trying to sort an array according other array. More specifically, sort ε\_ according Z. NN = 6 Z = rand(NN) ε\_= rand(NN) teste = \[ Z\[sortperm(Z)\] ε\_\[sortperm(ε\_)\] \] test\_f(Z) = teste\[teste\[:,1\] .== Z , 2\] ε\_ …

---

## [Fastest way to permute Array, given some permutation](https://discourse.julialang.org/t/fastest-way-to-permute-array-given-some-permutation/49687)

<div class="topic-metadata">

**Author:** [@DavidBerghaus](https://discourse.julialang.org/u/DavidBerghaus)\
**Replies:** 13\
**Last updated:** [September 12, 2021, 1:06pm UTC](https://discourse.julialang.org/t/fastest-way-to-permute-array-given-some-permutation/49687 "2021-09-12T13:06:19Z")

</div>

I wonder what the fastest way is to apply a permutation to an array. Three approaches that I checked are: julia\> A = rand(10000); julia\> permutation = sortperm(A); julia\> @btime $A\[$permutation\]; 11.700 μs (3 alloca…

---

## [Complex number sort](https://discourse.julialang.org/t/complex-number-sort/61417)

<div class="topic-metadata">

**Author:** [@cepheid](https://discourse.julialang.org/u/cepheid)\
**Replies:** 3\
**Last updated:** [May 19, 2021, 1:30pm UTC](https://discourse.julialang.org/t/complex-number-sort/61417 "2021-05-19T13:30:22Z")

</div>

I want to sort the complex vector as the lexicographically order, that is first the real part from large to small, the same real part, image part from small to large. julia\> a = ComplexF64\[-0.05050274530206651 + 0.60138…

---

## [Sortperm issue?](https://discourse.julialang.org/t/sortperm-issue/48351)

<div class="topic-metadata">

**Author:** [@dmetivie](https://discourse.julialang.org/u/dmetivie)\
**Replies:** 2\
**Last updated:** [October 14, 2020, 9:25am UTC](https://discourse.julialang.org/t/sortperm-issue/48351 "2020-10-14T09:25:04Z")

</div>

I work with Julia 1.5.1 on Linux. I have this array x = \[0.3575631591952295; -1.2891687824408367; -0.5123400980902758; -1.61271953171407; 1.0854706981323956; 0.2748568949784879;…

---

## [Any way to speed up sorting a dataframe? A more efficient sortperm would be great](https://discourse.julialang.org/t/any-way-to-speed-up-sorting-a-dataframe-a-more-efficient-sortperm-would-be-great/41995)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 2\
**Last updated:** [June 25, 2020, 9:55am UTC](https://discourse.julialang.org/t/any-way-to-speed-up-sorting-a-dataframe-a-more-efficient-sortperm-would-be-great/41995 "2020-06-25T09:55:46Z")

</div>

Consideirng a DataFrame using DataFrames using Random: randstring M = 100\_000\_000 str\_base = \[randstring(8) for i in 1:1\_000\_000\] df = DataFrame(int = rand(Int32, M), float=rand(M), str = rand(str\_base, M)) @time sort!…

---

## [\[ANN\]: SortingLab.jl 0.2.2 - 5x faster Sort and Sort Perm for \`Vector{Union{Missing, T}}\`](https://discourse.julialang.org/t/ann-sortinglab-jl-0-2-2-5x-faster-sort-and-sort-perm-for-vector-union-missing-t/31704)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 2\
**Last updated:** [December 1, 2019, 10:20pm UTC](https://discourse.julialang.org/t/ann-sortinglab-jl-0-2-2-5x-faster-sort-and-sort-perm-for-vector-union-missing-t/31704 "2019-12-01T22:20:36Z")

</div>

Do you want 5x faster sort and sortperm for Vector{Union{T, Missing}}? You can with SortingLab.jl! Simply use SortingLab.jl’s fsort and fsortperm to enjoy the benefits. Benchmarks Please note that SortingAlgorithms.j…

---

## [Sortperm slow test case and fix suggestion](https://discourse.julialang.org/t/sortperm-slow-test-case-and-fix-suggestion/23498)

<div class="topic-metadata">

**Author:** [@John\_Olsson](https://discourse.julialang.org/u/John_Olsson)\
**Replies:** 12\
**Last updated:** [April 28, 2019, 2:16pm UTC](https://discourse.julialang.org/t/sortperm-slow-test-case-and-fix-suggestion/23498 "2019-04-28T14:16:23Z")

</div>

is this a bug? a = vcat(zeros(Float32,1\_000\_000),ones(Float32,1\_000\_000)); @time sortperm(a,alg=QuickSort); 0.049065 seconds (8 allocations: 304 bytes) a = vcat(ones(Float32,1\_000\_000),zeros(Float32,1\_000\_000)); @time…

---

## [How to sort two or more lists at once?](https://discourse.julialang.org/t/how-to-sort-two-or-more-lists-at-once/12073)

<div class="topic-metadata">

**Author:** [@djsegal](https://discourse.julialang.org/u/djsegal)\
**Replies:** 12\
**Last updated:** [March 8, 2019, 10:43am UTC](https://discourse.julialang.org/t/how-to-sort-two-or-more-lists-at-once/12073 "2019-03-08T10:43:44Z")

</div>

Let’s say you have: cur\_x = shuffle(1:10) cur\_y = rand(10) And you want to sort cur\_x in the usual fashion, but drag cur\_y along for the ride. How do you – in one line – zip(cur\_x, cur\_y) and sort! by cur\_x? // so in…

---

## [\[ANN\] SortingLab.jl - fast sorting algorithms for strings and CategoricalArrays](https://discourse.julialang.org/t/ann-sortinglab-jl-fast-sorting-algorithms-for-strings-and-categoricalarrays/19653)

<div class="topic-metadata">

**Author:** [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Replies:** 2\
**Last updated:** [January 15, 2019, 10:12pm UTC](https://discourse.julialang.org/t/ann-sortinglab-jl-fast-sorting-algorithms-for-strings-and-categoricalarrays/19653 "2019-01-15T22:12:43Z")

</div>

I have updated the package to support Julia v1. There is no-intention of supporting Julia v0.6. Benchmarks Example usage using SortingLab; import Test: @test N = 1\_000\_000; K = 100; # faster string sort svec = …

---

## [Sorting lines by ID seems slow](https://discourse.julialang.org/t/sorting-lines-by-id-seems-slow/18705)

<div class="topic-metadata">

**Author:** [@tblz](https://discourse.julialang.org/u/tblz)\
**Replies:** 2\
**Last updated:** [December 16, 2018, 3:18am UTC](https://discourse.julialang.org/t/sorting-lines-by-id-seems-slow/18705 "2018-12-16T03:18:26Z")

</div>

Am trying to sort a file that looks like this: sc285168\_1 # 660 # 1046 # -1 # ID=285168\_1;partial=00; sc29363\_1 # 57 # 887 # 1 # ID=29363\_1;partial=00; sc316197\_1 # 17 # 418 # 1 # ID=316197\_1;partial=00; sc273994\_1 …

---

## [Sort by index an array](https://discourse.julialang.org/t/sort-by-index-an-array/18608)

<div class="topic-metadata">

**Author:** [@Elmer\_Cusipuma](https://discourse.julialang.org/u/Elmer_Cusipuma)\
**Replies:** 1\
**Last updated:** [December 12, 2018, 6:48pm UTC](https://discourse.julialang.org/t/sort-by-index-an-array/18608 "2018-12-12T18:48:27Z")

</div>

Which Julia’s function returns the indexes that would sort an array? a = \[0.4, 0.8, 0.2\] I would like to get a result like that: order = \[3,1,2\] so that a\[order\] 3-element Array{Float64,1}: 0.2 0.4 0.8

[Next page](https://discourse.julialang.org/tag/sortperm/150.md?match_all_tags=true&page=1&tags%5B%5D=sortperm)
