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

后端 未结 5 1016
你的背包
你的背包 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:28

    I know its old but how about

    [sum(zd .== i) for i in unique(zd)]

    in a short test it performed better than your initial function (time and memory wise).

    Caution: result not sorted!

提交回复
热议问题