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

**URL:** <https://discourse.julialang.org/t/map-and-slice-dont-preserve-the-size-of-an-array/58987>\
**Category:** General Usage\
**Tags:** broadcast, array, arrays\
**Created:** [April 10, 2021, 3:42pm UTC](https://discourse.julialang.org/t/map-and-slice-dont-preserve-the-size-of-an-array/58987 "2021-04-10T15:42:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sunny](https://avatars.discourse-cdn.com/v4/letter/s/7c8e57/32.png) [@Sunny](https://discourse.julialang.org/u/Sunny)\
**Post date:** [April 10, 2021, 3:42pm UTC](https://discourse.julialang.org/t/map-and-slice-dont-preserve-the-size-of-an-array/58987/1 "2021-04-10T15:42:02Z")

</div>

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

```julia
(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)?

---

<div class="post-metadata">

**Author:** ![Peter\_Adelman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/peter_adelman/32/11907_2.png) [@Peter\_Adelman](https://discourse.julialang.org/u/Peter_Adelman)\
**Post date:** [April 10, 2021, 4:23pm UTC](https://discourse.julialang.org/t/map-and-slice-dont-preserve-the-size-of-an-array/58987/2 "2021-04-10T16:23:06Z")

</div>

Try this instead:

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

```
