Count how many different values a list takes in Mathematica

后端 未结 4 1681
梦谈多话
梦谈多话 2021-02-08 02:45

I would like to get the number of different values found in a List.

For example:

The output for the List a={1,2,3,4,5} would be 5 whereas it would b

4条回答
  •  粉色の甜心
    2021-02-08 03:22

    CountDistinct[a]
    

    would also do the trick, which is a function introduced in Mathematica 10.0, a function equivalent to

    Length[DeleteDuplicates[a]]
    

提交回复
热议问题