# Does Julia have a generic way to find nonzero elemements of arrays?

**URL:** <https://discourse.julialang.org/t/does-julia-have-a-generic-way-to-find-nonzero-elemements-of-arrays/49666>\
**Category:** General Usage\
**Tags:** question, linearalgebra, sparse\
**Created:** [November 6, 2020, 4:51am UTC](https://discourse.julialang.org/t/does-julia-have-a-generic-way-to-find-nonzero-elemements-of-arrays/49666 "2020-11-06T04:51:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Oscar\_Smith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oscar_smith/32/25343_2.png) [@Oscar\_Smith](https://discourse.julialang.org/u/Oscar_Smith)\
**Post date:** [November 6, 2020, 4:51am UTC](https://discourse.julialang.org/t/does-julia-have-a-generic-way-to-find-nonzero-elemements-of-arrays/49666/1 "2020-11-06T04:51:30Z")

</div>

In [https://github.com/JuliaLang/julia/pull/38315#issuecomment-722623188](https://github.com/JuliaLang/julia/pull/38315#issuecomment-722623188) I suggested iterating over nonzero values as a possible efficient generic constructor for `SparseMatrix` I then proceed to realize that there isn’t such a function that works generically. `SparseArrays` has `findnz`, but it only seems to be defined for `SparseMatrixCSC` and `SparseVector`. Why is this? This feels like it would be a really useful method to have for generic structured arrays.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [November 6, 2020, 11:00am UTC](https://discourse.julialang.org/t/does-julia-have-a-generic-way-to-find-nonzero-elemements-of-arrays/49666/2 "2020-11-06T11:00:23Z")

</div>

TODO: finish [ArrayIteration](https://github.com/timholy/ArrayIteration.jl). I just haven’t really needed it for my own work.
