Equal method to matlab unique in rows

Hello everyboday, I not found the equal method “unique(x,‘rows’)” in Julia to matlab. Does it know anybody ? Thanks.

I’m not sure if this is exactly what the Matlab function does, but unique(eachrow(x)) would give you a vector of unique rows.

The suggested unique(eachrow(x)) will work, but return a vector of views into the original matrix. To get a matrix (like you would in Matlab), use unique(x, dims=1):

julia> x = [1 2 3; 4 5 6; 1 2 3]
3×3 Matrix{Int64}:
 1  2  3
 4  5  6
 1  2  3

julia> unique(eachrow(x))
2-element Vector{SubArray{Int64, 1, Matrix{Int64}, Tuple{Int64, Base.Slice{Base.OneTo{Int64}}}, true}}:
 [1, 2, 3]
 [4, 5, 6]

julia> unique(x, dims=1)
2×3 Matrix{Int64}:
 1  2  3
 4  5  6

1 Like