# Is it possible to store the result of a distribution function at an instant in an array?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-store-the-result-of-a-distribution-function-at-an-instant-in-an-array/75620>\
**Category:** New to Julia\
**Tags:** arrays, distributions\
**Created:** [February 2, 2022, 3:21am UTC](https://discourse.julialang.org/t/is-it-possible-to-store-the-result-of-a-distribution-function-at-an-instant-in-an-array/75620 "2022-02-02T03:21:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![CentraCep](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/centracep/32/32454_2.png) [@CentraCep](https://discourse.julialang.org/u/CentraCep)\
**Post date:** [February 2, 2022, 3:21am UTC](https://discourse.julialang.org/t/is-it-possible-to-store-the-result-of-a-distribution-function-at-an-instant-in-an-array/75620/1 "2022-02-02T03:21:06Z")

</div>

Is there a way one can store the instantaneous results of a probability distribution function (like the ones in [Distributions.jl](https://juliastats.org/Distributions.jl/stable/) into a data structure? Here is how my code is set up right now attempting to do this:

```julia
dt = 10^(-5) # timestep
t = range(0, 1.0, step=dt)

f_s = zeros(length(t)+1)
f_s[1] = Uniform(0,1)

```

```julia
MethodError: Cannot `convert` an object of type Uniform{Float64} to an object of type Float64
Closest candidates are:
  convert(::Type{T}, ::T) where T<:Number at C:\Users\Acer\AppData\Local\Programs\Julia-1.7.0\share\julia\base\number.jl:6
  convert(::Type{T}, ::Number) where T<:Number at C:\Users\Acer\AppData\Local\Programs\Julia-1.7.0\share\julia\base\number.jl:7
  convert(::Type{T}, ::Base.TwicePrecision) where T<:Number at C:\Users\Acer\AppData\Local\Programs\Julia-1.7.0\share\julia\base\twiceprecision.jl:262

```

The reason I ask this is because I plan to numerically solve a linear partial differential equation which essentially starts with some given distribution, but if one timesteps it enough, it is supposed to tend to a chi distribution with 3 degrees of freedom (if interested or seeking more information, I could share more details).

---

<div class="post-metadata">

**Author:** ![lawless-m](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lawless-m/32/30869_2.png) [@lawless-m](https://discourse.julialang.org/u/lawless-m)\
**Post date:** [February 2, 2022, 7:06am UTC](https://discourse.julialang.org/t/is-it-possible-to-store-the-result-of-a-distribution-function-at-an-instant-in-an-array/75620/2 "2022-02-02T07:06:14Z")

</div>

The error message here is telling you that `fs_1[1]` is an element of an Array of `Float64` but the value you are trying to store in it, is of type `Uniform{Float64}`.

instead of `f_s = zeros....` do  
`f_s = Vector{Uniform{Float64}}(undef, length(t)+1)`

or if you _really_ need them to be initialized to zero

`[Uniform{Float64}(0.0,0.0) for _ in 1:length(t)+1]`
