# Filter out the nonzero elements in a dense axis array

**URL:** https://discourse.julialang.org/t/filter-out-the-nonzero-elements-in-a-dense-axis-array/23252
**Category:** General Usage
**Created:** [April 17, 2019, 4:49pm UTC](https://discourse.julialang.org/t/filter-out-the-nonzero-elements-in-a-dense-axis-array/23252 "2019-04-17T16:49:20Z")
**Posts on this page:** 1
**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 17, 2019, 4:49pm UTC](https://discourse.julialang.org/t/filter-out-the-nonzero-elements-in-a-dense-axis-array/23252/1 "2019-04-17T16:49:20Z")

</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 elements are obvious, but when I have a very large network, f1 becomes a very large array, how could I filter out the nonzero elements of a large f1?
