Map and slice don't preserve the size of an array

I’m implementing element-wise multiplication
and want to multiply array of size (2,8) with array of size (N,2,8).
When I’m making this as follows

(map(x -> rand(3,4) .* x, eachslice(rand(1,3,4), dims=1)))[end]

I’m losing the 1st dim.
How is it supposed to be done correctly in order to preserve the original dimension (N,2,8)?

Try this instead:

mapslices(x -> rand(3,4).*x, rand(1,3,4), dims=[2,3])
2 Likes