Count instances of each unique integer in a vector in 1 line of code?

后端 未结 5 1011
你的背包
你的背包 2021-01-17 15:08

Is there a slick way to rewrite this Julia function, perhaps using just 1 line of code, without making it much slower? (I just started using Julia. It\'s great!) K

5条回答
  •  清酒与你
    2021-01-17 15:41

    There are a bunch of counting functions included in the StatsBase.jl package. Your tally function is equivalent to counts(zd, 1:K).

    There are also methods for counting unique elements of types other than integer, too, such as countmap, which returns a dictionary mapping unique values to their number of occurrences.

提交回复
热议问题