# What does this mean? findnz(A::AbstractMatrix)\` is deprecated, use \`begin

**URL:** <https://discourse.julialang.org/t/what-does-this-mean-findnz-a-abstractmatrix-is-deprecated-use-begin/15521>\
**Category:** New to Julia\
**Created:** [September 26, 2018, 4:42pm UTC](https://discourse.julialang.org/t/what-does-this-mean-findnz-a-abstractmatrix-is-deprecated-use-begin/15521 "2018-09-26T16:42:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![threadedblue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/threadedblue/32/19247_2.png) [@threadedblue](https://discourse.julialang.org/u/threadedblue)\
**Post date:** [September 26, 2018, 4:42pm UTC](https://discourse.julialang.org/t/what-does-this-mean-findnz-a-abstractmatrix-is-deprecated-use-begin/15521/1 "2018-09-26T16:42:49Z")

</div>

I am having trouble understanding this:

` **Warning:** `findnz(A::AbstractMatrix)`is deprecated, use`begin  
**│** I = findall(!iszero, A)  
**│** (getindex.(I, 1), getindex.(I, 2), A[I])  
**│** end` instead. **│** `

What does it mean?  
Thanks

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 26, 2018, 4:47pm UTC](https://discourse.julialang.org/t/what-does-this-mean-findnz-a-abstractmatrix-is-deprecated-use-begin/15521/2 "2018-09-26T16:47:36Z")

</div>

It is telling you to write

```julia
I = findall(!iszero, A)
getindex.(I, 1), getindex.(I, 2), A[I]

```

instead of `findnz` because this will give you the exact output that `findnz` used to do.

```julia
julia> A = rand(0:1, 2, 2)
2×2 Array{Int64,2}:
 0 0
 1 1

julia> I = findall(!iszero, A)
2-element Array{CartesianIndex{2},1}:
 CartesianIndex(2, 1)
 CartesianIndex(2, 2)

julia> getindex.(I, 1), getindex.(I, 2), A[I]
([2, 2], [1, 2], [1, 1])

```

However, it is rarely needed to do this destructuring of `I`.

---

<div class="post-metadata">

**Author:** ![threadedblue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/threadedblue/32/19247_2.png) [@threadedblue](https://discourse.julialang.org/u/threadedblue)\
**Post date:** [September 26, 2018, 7:46pm UTC](https://discourse.julialang.org/t/what-does-this-mean-findnz-a-abstractmatrix-is-deprecated-use-begin/15521/3 "2018-09-26T19:46:25Z")

</div>

Got it! It was the begin and end bits that threw me. I have findnz sprayed through out my code base. I am tempted to simply implement my own findnz using the new replacement code from above. Nevertheless, findnz must have been deprecated for a reason. Would rolling my own be ill advised.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [September 26, 2018, 7:49pm UTC](https://discourse.julialang.org/t/what-does-this-mean-findnz-a-abstractmatrix-is-deprecated-use-begin/15521/4 "2018-09-26T19:49:38Z")

</div>

You can read a little bit of background at [https://github.com/JuliaLang/julia/pull/27869](https://github.com/JuliaLang/julia/pull/27869).

You can always pack up the code above in your own `findnz` function and at some later point think about if you want to refactor your code to not need it.

---

<div class="post-metadata">

**Author:** ![tkoolen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tkoolen/32/1603_2.png) [@tkoolen](https://discourse.julialang.org/u/tkoolen)\
**Post date:** [September 26, 2018, 8:31pm UTC](https://discourse.julialang.org/t/what-does-this-mean-findnz-a-abstractmatrix-is-deprecated-use-begin/15521/5 "2018-09-26T20:31:25Z")

</div>

I think it would be nice to have a `Base.@deprecate` version that allows you to provide a bit more information. Right now, either you use `Base.@deprecate`, which is convenient but can result in somewhat convoluted replacement suggestions like this, or you manually use `Base.depwarn`, which has the opposite problem.
