yaodao vang
yaodao vang

Reputation: 298

how to identify the number of unique elements in two sparate vector?

I have two very long distict vectors (that are not started at 1) and wanted to know how many element I have in totall:

For example, the first few elements are:

A = [220,202,122,212,141,144,174,154,127,888,758,768,455,665]

B = [555,555,661,661,252,252,789,789,789,789,789,365,369,789]

My question:

How to find this out? the number of unique element in A union B?

Upvotes: 1

Views: 150

Answers (1)

Silvio Mayolo
Silvio Mayolo

Reputation: 70297

union and length are both built-in to Julia. And union is a set union which removes duplicates, even when applied to vectors. Consider

println(length(union(A, B)))

or, if you're feeling particularly snazzy

println(length(A ∪ B))

Upvotes: 3

Related Questions