# Find n smallest values in an n dims array

**URL:** <https://discourse.julialang.org/t/find-n-smallest-values-in-an-n-dims-array/81092>\
**Category:** New to Julia\
**Tags:** question, sort, sortperm, arrays, cartesianindices\
**Created:** [May 15, 2022, 12:07pm UTC](https://discourse.julialang.org/t/find-n-smallest-values-in-an-n-dims-array/81092 "2022-05-15T12:07:22Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![marianoarnaiz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/marianoarnaiz/32/19377_2.png) [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Post date:** [May 15, 2022, 7:11pm UTC](https://discourse.julialang.org/t/find-n-smallest-values-in-an-n-dims-array/81092/11 "2022-05-15T19:11:19Z")

</div>

> [@mkitti](#):
>
> ```julia
> function arg_n_smallest_values(A::AbstractArray{T,N}, n::Integer) where {T,N}
> perm = sortperm(vec(A))
> ci = CartesianIndices(A)
> return ci[perm[1:n]]
> end
> 
> ```

Thanks guys. This should be included somewhere in Julia

---

_[View the full topic](https://discourse.julialang.org/t/find-n-smallest-values-in-an-n-dims-array/81092)._
