Convert n number of 1*1 matrices to one n*1 vector

k=collect(0:0.1:1)

u is a neural network.

pred=(u.(k))

11-element Vector{Matrix{Float64}}:
[-0.48909483506995793]
[-0.46596887211781113]
[-0.44329630895872524]
[-0.4211157735999599]
[-0.39946203623807897]
[-0.37836588996089027]
[-0.3578540892654915]
[-0.3379493434394113]
[-0.3186703608096747]
[-0.30003193904325304]
[-0.28204509608735767]

I want the values to be a single vector. Please help

mapreduce(vec, vcat, pred)
3 Likes
v = getindex.(pred, 1, 1)
2 Likes

ah, yes

only.(pred)
2 Likes

Or first.(pred) if you want this to work on all 1.x Julia versions.

4 Likes

Thank you, everyone

You don’t (and in fact rarely) need the collect step.

1 Like

Using splatting:

vec(vcat(pred...))
1 Like