# How do findall ,findmax ,findmin, argmax, argmin work on SparseArrays/SparseMatrixCSC

**URL:** <https://discourse.julialang.org/t/how-do-findall-findmax-findmin-argmax-argmin-work-on-sparsearrays-sparsematrixcsc/66735>\
**Category:** Performance\
**Tags:** sparse\
**Created:** [August 20, 2021, 2:49pm UTC](https://discourse.julialang.org/t/how-do-findall-findmax-findmin-argmax-argmin-work-on-sparsearrays-sparsematrixcsc/66735 "2021-08-20T14:49:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [August 20, 2021, 2:49pm UTC](https://discourse.julialang.org/t/how-do-findall-findmax-findmin-argmax-argmin-work-on-sparsearrays-sparsematrixcsc/66735/1 "2021-08-20T14:49:10Z")

</div>

Do `findall``findmax` ,`findmin`, `argmax`, `argmin` work on SparseArrays by  
convert `sparse` to `Matrix` type before doing operations on these functions? If yes, is the computational cost too much of converting?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 20, 2021, 2:55pm UTC](https://discourse.julialang.org/t/how-do-findall-findmax-findmin-argmax-argmin-work-on-sparsearrays-sparsematrixcsc/66735/2 "2021-08-20T14:55:40Z")

</div>

No, there is no conversion, and findall operates only on the nonzero elements if the predicate is false for zero.

---

<div class="post-metadata">

**Author:** ![yewalenikhil65](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yewalenikhil65/32/26873_2.png) [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Post date:** [August 20, 2021, 3:43pm UTC](https://discourse.julialang.org/t/how-do-findall-findmax-findmin-argmax-argmin-work-on-sparsearrays-sparsematrixcsc/66735/3 "2021-08-20T15:43:55Z")

</div>

> findall operates only on the nonzero elements if the predicate is false for zero.

Does this mean something like `findall(!iszero, some_matrix)` ? where some\_matrix is `SparseMatrixCSC`

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [August 20, 2021, 5:37pm UTC](https://discourse.julialang.org/t/how-do-findall-findmax-findmin-argmax-argmin-work-on-sparsearrays-sparsematrixcsc/66735/4 "2021-08-20T17:37:49Z")

</div>

> [@yewalenikhil65](#):
>
> Does this mean something like `findall(!iszero, some_matrix)` ? where some\_matrix is `SparseMatrixCSC`

In particular, if you look at the source code ([https://github.com/JuliaLang/julia/blob/0224c42bce6daec1b5580b8a8a6b43f9437d2cee/stdlib/SparseArrays/src/sparsematrix.jl#L1544-L1563](https://github.com/JuliaLang/julia/blob/0224c42bce6daec1b5580b8a8a6b43f9437d2cee/stdlib/SparseArrays/src/sparsematrix.jl#L1544-L1563)), the `findall` function first calls `predicate(0)` with the user-specified `predicate` function. If this returns `false`, then it subsequently calls the `predicate` only on the sparse nonzero elements.

For example, this means that `findall(x -> abs(x) > 0.1, A)` is efficient for a sparse matrix, with complexity proportional to the number of nonzero entries of `A`.
