gpt4 book ai didi

julia - Julia 的MATLAB历史计数?

转载 作者:行者123 更新时间:2023-12-05 00:52:10 29 4
gpt4 key购买 nike

在 MATLAB 中,[N,edges,bin] = histcounts (___) 可以获得相应元素的 bin 索引。 Julia 有什么等价的功能吗?谢谢!

我已经尝试过 StatsBase.jl 中的 Histogram 和 NaNStatistics.jl 中的 histcounts。似乎他们都无法获得 bin 索引。

最佳答案

使用直方图的边缘尝试 searchsortedlast:

julia> dat = rand(20);

julia> h = fit(Histogram, dat, nbins=5)
Histogram{Int64, 1, Tuple{StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}, Int64}}}
edges:
0.2:0.2:1.0
weights: [8, 4, 3, 5]
closed: left
isdensity: false

julia> searchsortedlast.(Ref(h.edges[1]), dat)'
1×20 adjoint(::Vector{Int64}) with eltype Int64:
4 3 1 2 4 1 1 2 1 3 1 3 4 2 1 4 4 2 1 1

关于julia - Julia 的MATLAB历史计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70606493/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com