I’m trying to do a sample of a string array, incorporating weights for each of the elements of the array. Specifically,
new_name_event = sample(events,Weights(dict_betas_choices[string(new_player)][new_zone][string(new_time)][string(new_loc)][string(new_res)]))
>ERROR:
MethodError: no method matching Weights(::Array{Any,1}, ::Float64)
Closest candidates are:
Weights(!Matched::var"#18#V", ::var"#16#S") where {var"#16#S"<:Real, var"#17#T"<:Real, var"#18#V"<:AbstractArray{var"#17#T",1}} at C:\Users\semed\.julia\packages\StatsBase\ZxhK8\src\weights.jl:13
Weights(::Any) at C:\Users\semed\.julia\packages\StatsBase\ZxhK8\src\weights.jl:16
Stacktrace:
[1] Weights(::Array{Any,1}) at C:\Users\semed\.julia\packages\StatsBase\ZxhK8\src\weights.jl:16
[2] top-level scope at .\In[22]:62
[3] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091
Where,
println(events, typeof(events))
>["Shot", "Duel", "Pass"]Array{String,1}
pesos = dict_betas_choices[string(new_player)][new_zone][string(new_time)][string(new_loc)][string(new_res)]
println(pesos, typeof(pesos), typeof(pesos[1]))
>Any[0.00114591, 0.69774462, 0.30110947] Array{Any,1} Float64
This should fix it in your case:
Float64.(dict_betas_choices[string(new_player)][new_zone][string(new_time)][string(new_loc)][string(new_res)])
If it errors it would mean that your data are not consisting of only numbers.
In general you should fix the data in the source to have eltype not Any but some real number type, e.g. Float64 as suggested above (this should be fixed at data structure creation time).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With