# Filter out the nonzero values in a dense axis array

**URL:** <https://discourse.julialang.org/t/filter-out-the-nonzero-values-in-a-dense-axis-array/22883>\
**Category:** General Usage\
**Created:** [April 7, 2019, 5:08pm UTC](https://discourse.julialang.org/t/filter-out-the-nonzero-values-in-a-dense-axis-array/22883 "2019-04-07T17:08:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yan25y](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yan25y](https://discourse.julialang.org/u/yan25y)\
**Post date:** [April 7, 2019, 5:08pm UTC](https://discourse.julialang.org/t/filter-out-the-nonzero-values-in-a-dense-axis-array/22883/1 "2019-04-07T17:08:53Z")

</div>

![question%20for%20Julia%20(1)](https://global.discourse-cdn.com/julialang/original/3X/e/d/ed27860d8bda36a07946010aafcf50868e61051d.png)  
Could someone help me figuring out how to filter out the nonzero values and its corresponding keys in this dense array?  
Thank you!

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [April 7, 2019, 5:56pm UTC](https://discourse.julialang.org/t/filter-out-the-nonzero-values-in-a-dense-axis-array/22883/2 "2019-04-07T17:56:03Z")

</div>

Please quote your code and post an MWE.

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![yan25y](https://avatars.discourse-cdn.com/v4/letter/y/94ad74/32.png) [@yan25y](https://discourse.julialang.org/u/yan25y)\
**Post date:** [April 17, 2019, 4:47pm UTC](https://discourse.julialang.org/t/filter-out-the-nonzero-values-in-a-dense-axis-array/22883/3 "2019-04-17T16:47:09Z")

</div>

Here is the quoted code for a network problem that I’m working on

```julia
using JuMP 
using Gurobi

supply_nodes=["i1","i2","i3"]
s=[4,3,2]
s_dict=Dict()

for i in 1:length(supply_nodes)
   s_dict[supply_nodes[i]]=s[i]
end

demand_nodes=["j1","j2","j3"]
d=[3,5,1]
d_dict=Dict()
for i in 1:length(demand_nodes)
   d_dict[demand_nodes[i]]=d[i]
end

dist=[1 2 3;2 1 2;3 2 1]
dist_dict=Dict()
for i in 1:length(supply_nodes)
    for j in 1:length(demand_nodes)
        dist_dict[supply_nodes[i],demand_nodes[j]]=dist[i,j]   
    end
end

Demand=5

model=Model(with_optimizer(Gurobi.Optimizer))
@variable(model,f1[supply_nodes,demand_nodes]>=0)
@constraint (model,sum(f1[i,j] for i in supply_nodes, j in demand_nodes)==Demand)
for j in demand_nodes
    @constraint(model,sum(f1[i,j] for i in supply_nodes <=d_dict[j]
end

for i in supply_nodes
   @constraint(model,sum(f1[i,j] for j in demand_nodes <= s_dict[i]
end

@objective(model, Min, sum(f1[i,j]*dist_dict[i,j] for i in supply_nodes, j in demand_nodes))

optimize!(model) 

JuMP.value.(f1) 

```

In this simplified case, nonzero f1 are obvious to see, but when I have a very large network, f1 could be a very large array, how could I filter out the nonzero elements of f1?
