# How to leave only unique rows of array

**URL:** <https://discourse.julialang.org/t/how-to-leave-only-unique-rows-of-array/112332>\
**Category:** General Usage\
**Created:** [March 30, 2024, 4:46pm UTC](https://discourse.julialang.org/t/how-to-leave-only-unique-rows-of-array/112332 "2024-03-30T16:46:07Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [March 30, 2024, 5:53pm UTC](https://discourse.julialang.org/t/how-to-leave-only-unique-rows-of-array/112332/2 "2024-03-30T17:53:05Z")

</div>

See [Unique (indices) method similar to MATLAB](https://discourse.julialang.org/t/unique-indices-method-similar-to-matlab/34446) — for example, if you have a matrix `a` and you want the rows corresponding to whether columns 1 and 2 are unique, you could do:

```julia
julia> a = [ "Kalinka" "surname"
        "Kalinka" "surname"
        "Kalinka" "surname"
        "Kalinka" "geographical_name"
        "Kalinka" "geographical_name"
        "Kalinka" "geographical_name"
        "Kalinka" "geographical_name"
        "Kalinko" "surname"
        "Kalinko" "surname"
        "Kalinka" "name"
        "Kalinka" "name"];

julia> idx = unique(i -> (a[i,1], a[i,2]), axes(a, 1))
4-element Vector{Int64}:
  1
  4
  8
 10

julia> a[idx,:] # rows where (col1, col2) are unique
4×2 Matrix{String}:
 "Kalinka" "surname"
 "Kalinka" "geographical_name"
 "Kalinko" "surname"
 "Kalinka" "name"

```

```julia

```

---

_[View the full topic](https://discourse.julialang.org/t/how-to-leave-only-unique-rows-of-array/112332)._
