2017-02-07 4 views
1

、それは、高性能オブジェクトcollections.Counterを使用して、リスト内の項目をカウントすることが可能です:JuliaにCounterオブジェクトがありますか? Pythonでは

>>> from collections import Counter 
>>> l = [1,1,2,4,1,5,12,1,51,2,5] 
>>> Counter(l) 
Counter({1: 4, 2: 2, 5: 2, 4: 1, 12: 1, 51: 1}) 

私はhttp://docs.julialang.org/en/latest/search.html?q=counterで検索しましたが、私はカウンターオブジェクトを見つけるように見えることはできません。

私はまたhttp://docs.julialang.org/en/latest/stdlib/collections.htmlを見ましたが、それも見つけられませんでした。

私はジュリアのヒストグラム機能を試してみた、それは非推奨メッセージの波を返しました:

> l = [1,1,2,4,1,5,12,1,51,2,5] 
> hist(l) 

[出]:

WARNING: sturges(n) is deprecated, use StatsBase.sturges(n) instead. 
in depwarn(::String, ::Symbol) at ./deprecated.jl:64 
in sturges(::Int64) at ./deprecated.jl:623 
in hist(::Array{Int64,1}) at ./deprecated.jl:646 
in include_string(::String, ::String) at ./loading.jl:441 
in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/liling.tan/.julia/v0.5/IJulia/src/execute_request.jl:175 
in eventloop(::ZMQ.Socket) at /Users/liling.tan/.julia/v0.5/IJulia/src/eventloop.jl:8 
in (::IJulia.##13#19)() at ./task.jl:360 
while loading In[65], in expression starting on line 1 
WARNING: histrange(...) is deprecated, use StatsBase.histrange(...) instead 
in depwarn(::String, ::Symbol) at ./deprecated.jl:64 
in histrange(::Array{Int64,1}, ::Int64) at ./deprecated.jl:582 
in hist(::Array{Int64,1}, ::Int64) at ./deprecated.jl:645 
in hist(::Array{Int64,1}) at ./deprecated.jl:646 
in include_string(::String, ::String) at ./loading.jl:441 
in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/liling.tan/.julia/v0.5/IJulia/src/execute_request.jl:175 
in eventloop(::ZMQ.Socket) at /Users/liling.tan/.julia/v0.5/IJulia/src/eventloop.jl:8 
in (::IJulia.##13#19)() at ./task.jl:360 
while loading In[65], in expression starting on line 1 
WARNING: hist(...) and hist!(...) are deprecated. Use fit(Histogram,...) in StatsBase.jl instead. 
in depwarn(::String, ::Symbol) at ./deprecated.jl:64 
in #hist!#994(::Bool, ::Function, ::Array{Int64,1}, ::Array{Int64,1}, ::FloatRange{Float64}) at ./deprecated.jl:629 
in hist(::Array{Int64,1}, ::FloatRange{Float64}) at ./deprecated.jl:644 
in hist(::Array{Int64,1}, ::Int64) at ./deprecated.jl:645 
in hist(::Array{Int64,1}) at ./deprecated.jl:646 
in include_string(::String, ::String) at ./loading.jl:441 
in execute_request(::ZMQ.Socket, ::IJulia.Msg) at /Users/liling.tan/.julia/v0.5/IJulia/src/execute_request.jl:175 
in eventloop(::ZMQ.Socket) at /Users/liling.tan/.julia/v0.5/IJulia/src/eventloop.jl:8 
in (::IJulia.##13#19)() at ./task.jl:360 
while loading In[65], in expression starting on line 1 

**Is there a Counter object in Julia?** 

答えて

2

あなたはジュリア0.5 +、ヒストグラムを使用している場合、関数has been deprecatedがあり、代わりにStatsBase.jlモジュールを使用することになっています。また、警告に記載されています。

警告:hist(...)およびhist!(...)は非推奨です。代わりにStatsBase.jlにfit(Histogram、...)を使用してください。

しかし、あなたはStatsBase.jlを使用している場合は、おそらくcountmapはあなたが必要なものに近いです:

julia> import StatsBase: countmap                                    

julia> countmap([1,1,2,4,1,5,12,1,51,2,5])                                  
Dict{Int64,Int64} with 6 entries: 
    4 => 1 
    2 => 2 
    5 => 2 
    51 => 1 
    12 => 1 
    1 => 4 
+0

ありがとう!どんなアイデアでも、StatsBaseは別のパッケージであり、ネイティブJulia 0.5の一部ではありませんか? – alvas

+1

@alvasそれは別のパッケージですが、パッケージをインストールするには 'Pkg.add()'が必要です。 – kennytm

+1

@alvas Base Juliaのサイズを縮小するために意図的な努力がなされているので、多くの機能はBaseにはありません。パッケージ化されても、パフォーマンスには影響しません。 – DNF

関連する問題