Returning vector of Distribution parameters

Hello, apologies if this is a very basic question, but I am still getting to grips with some elements of Julia.

I am generating an array of Gamma distributions. I want to pull the distribution parameters out to plot them. I am starting with this variable px:

19-element Vector{Any}:
 Gamma{Float64}(α=9.001672757969871, θ=0.030893295700556725)
 Gamma{Float64}(α=6.132503558978596, θ=0.041371593865741865)
 Gamma{Float64}(α=8.198451607965989, θ=0.029230714826536285)
 Gamma{Float64}(α=6.048497748958801, θ=0.05071352552065335)

and I can do it like this:

α = Array{Float64,1}()
θ = Array{Float64,1}()  
for i=1:19

That then leaves me with two vectors α and θ, as I want.

But surely there must be a more direct way through indexing to pull out the α and θ elements of the distribution?


Try broadcasting getproperty

α = getproperty.(px, :α)
1 Like

Thank you! That works.

1 Like