If mydates isn’t empty, then the broadcast you’re asking for doesn’t really make sense because one side is an empty container. There are plenty of ways to instantiate a Vector of Vector{Float64}, but one possible way that I think illustrates the source of the error is
Dict(mydates .=> [Vector{Float64}() for _ in 1:length(mydates)])
The point about correctness is that you need to make sure that you allocate a fresh vector for each dictionary entry, and this is what comprehension does (that is why in the solution by @cgeoga also a comprehension had to be used)
You most likely wanted to write something like:
Dict(mydates .=> Ref(Vector{Float64}()))
unfortunately this would not be correct as dictionary values would be aliases.
Shouldn’t it be d = Dict (mydates. => Ref (Float64 [])) instead?
Can you explain in more detail, perhaps with examples, this fact: “as dictionary values would be aliases.”?
To be clear also, this isn’t just a feature of Ref. The docs on broadcasting comment on this: wrapping elements in a container changes the way that broadcasting works. So this also has the same issue:
julia> x = rand(5);
julia> t = Float64[];
julia> d = Dict(x .=> [t]);
julia> push!(t, 1.0)
1-element Vector{Float64}:
1.0
julia> d
Dict{Float64, Vector{Float64}} with 5 entries:
0.251673 => [1.0]
0.877861 => [1.0]
0.766795 => [1.0]
0.814601 => [1.0]
0.733239 => [1.0]
Note that if you just tried to make Dict(x .=> t) before push!-ing to it, you’d get your error. But after push!-ing, you get this:
So the way that broadcasting works here is actually a bit subtle.
EDIT: I’ve tried to be pretty focused on actually answering your question about broadcasting, but to be clear and for what it’s worth, I think @bkamins advice is best and that broadcasting just seems like a bit of a footgun here. That’s not how I’d choose to construct a Dict like this. But then, it’s your code and your use case and stuff, so take that for whatever it’s worth.