Reputation: 31
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
Upvotes: 3
Views: 142
Reputation: 69949
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).
Upvotes: 4