Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Julia, how to compute the mean (average) between two DateTime arrays?

Given two DateTime arrays of equal size, my solution to find the mean between each DateTime pair in Julia is as follows:

using Dates
d1 = [DateTime(2000,1,1,14), DateTime(2000,1,1,15), DateTime(2000,1,2,14) + Millisecond(1)] 
d2 = [DateTime(2000,1,1,13), DateTime(2000,1,1,12), DateTime(2000,1,2,10),] 

d1 .+ map(v -> Millisecond(round(v.value * 0.5)), d2 .- d1)

Is this actually the best way to do it? - I find it quite convoluted ...

H.M.

P.S. For the underlying issue, see this item at JuliaLang

like image 530
H.M. Müller Avatar asked Dec 28 '25 21:12

H.M. Müller


1 Answers

d1 .+ ((d2 .- d1) .÷2)

Where the items in d2 are after the ones in d1.

like image 154
Mark Avatar answered Dec 31 '25 18:12

Mark



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!