Converting a vector of static arrays

I have the following data structure:

using KiteUtils
syslog=demo_syslog(7)
syslog.Z

Output:

201-element Vector{StaticArrays.MVector{7, Float32}}:
 [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
 [0.0, 0.0007690057, 0.0030974336, 0.007050112, 0.012737092, 0.02031671, 0.030000001]
 [0.0, 0.0015380114, 0.006194867, 0.014100224, 0.025474183, 0.04063342, 0.060000002]
 [0.0, 0.002307017, 0.009292301, 0.021150336, 0.038211275, 0.060950134, 0.09]
 [0.0, 0.0030760227, 0.012389734, 0.028200448, 0.050948367, 0.08126684, 0.120000005]
 [0.0, 0.0038450283, 0.015487167, 0.03525056, 0.06368546, 0.101583555, 0.15]
 ⋮
 [0.0, 0.1499561, 0.60399956, 1.3747718, 2.483733, 3.9617586, 5.8500004]
 [0.0, 0.15072511, 0.60709697, 1.3818219, 2.49647, 3.9820752, 5.8800006]
 [0.0, 0.15149412, 0.6101944, 1.388872, 2.509207, 4.002392, 5.9100003]
 [0.0, 0.15226312, 0.6132918, 1.3959222, 2.521944, 4.022709, 5.9400005]
 [0.0, 0.15303212, 0.6163893, 1.4029722, 2.5346813, 4.0430255, 5.9700003]
 [0.0, 0.15380114, 0.6194867, 1.4100224, 2.5474184, 4.063342, 6.0000005]

I want to have an array z with the following content:

201-element view(::RecursiveArrayTools.VectorOfArray{Float32, 2, Vector{StaticArrays.MVector{7, Float32}}}, 7, :) with eltype Float32:
 0.0
 0.030000001
 0.060000002
 0.09
 0.120000005
 0.15
 ⋮
 5.8500004
 5.8800006
 5.9100003
 5.9400005
 5.9700003
 6.0000005

Is there an easy way to achieve that?

Maybe

last.(v)

Indeed, this works:

julia> last.(syslog.Z)
201-element Vector{Float32}:
 0.0
 0.030000001
 0.060000002
 0.09
 0.120000005
 0.15
 ⋮
 5.8500004
 5.8800006
 5.9100003
 5.9400005
 5.9700003
 6.0000005

Thank you!

Before I used:

julia> @view VectorOfArray(syslog.Z)[end,:]
201-element Vector{Float32}:
 0.0
 0.030000001
 0.060000002
 0.09
 0.120000005
 0.15
 ⋮
 5.8500004
 5.8800006
 5.9100003
 5.9400005
 5.9700003
 6.0000005

But your solution is much simpler and does not require an extra package…

1 Like