# Sorting a sparse axis array in JuMP

**URL:** https://discourse.julialang.org/t/sorting-a-sparse-axis-array-in-jump/57167
**Category:** Optimization (Mathematical)
**Tags:** question
**Created:** [March 15, 2021, 4:49am UTC](https://discourse.julialang.org/t/sorting-a-sparse-axis-array-in-jump/57167 "2021-03-15T04:49:30Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![priod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/priod/32/53099_2.png) [@priod](https://discourse.julialang.org/u/priod)
#### Post date: [March 15, 2021, 4:49am UTC](https://discourse.julialang.org/t/sorting-a-sparse-axis-array-in-jump/57167/1 "2021-03-15T04:49:30Z")

</div>

Hi,

I am using the JuMP model, after the optimization process, I have a sparse axis array, I need to sort this array in the descending direction. How can I sort this? Thanking you in advance for the suggestions.

 ![Capture](https://global.discourse-cdn.com/julialang/original/3X/2/4/242f28593220f6687102a3605d61a8264fc029c3.png)  
The image is attached with it.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [March 15, 2021, 5:44am UTC](https://discourse.julialang.org/t/sorting-a-sparse-axis-array-in-jump/57167/2 "2021-03-15T05:44:42Z")

</div>

Hi there! Take a read of [Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757). In particular, it’s easier to help if you provide a minimal working example and avoid using screenshots.

```nohighlight
y = [(k, value(Status[k]) for k in eachindex(Status)]
sort!(y, by = x -> x[2])

```

But it looks like you might want

```nohighlight
y = [k for k in eachindex(Status) if value(Status[k]) > 0.5]

```

---

<div class="post-metadata">

### Author: ![priod](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/priod/32/53099_2.png) [@priod](https://discourse.julialang.org/u/priod)
#### Post date: [March 15, 2021, 6:25am UTC](https://discourse.julialang.org/t/sorting-a-sparse-axis-array-in-jump/57167/3 "2021-03-15T06:25:32Z")

</div>

Thank you. It is working, but I also need to know, how can I get the values at only those indices where “i\<j”. for example (i,j) = value, only those indices where the value of “i” is less than “j”.

---

<div class="post-metadata">

### Author: ![odow](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/odow/32/28685_2.png) [@odow](https://discourse.julialang.org/u/odow)
#### Post date: [March 15, 2021, 7:23am UTC](https://discourse.julialang.org/t/sorting-a-sparse-axis-array-in-jump/57167/4 "2021-03-15T07:23:41Z")

</div>

There is nothing special about the keys of your SparseAxisArray – they’re just a Julia tuple. So you can go

```nohighlight
y = [(k, value(Status[k]) for k in eachindex(Status) if k[1] < k[2]]

```
