# Splatting specific dimension of multidimensional array?

**URL:** <https://discourse.julialang.org/t/splatting-specific-dimension-of-multidimensional-array/93089>\
**Category:** General Usage\
**Tags:** array\
**Created:** [January 17, 2023, 12:55pm UTC](https://discourse.julialang.org/t/splatting-specific-dimension-of-multidimensional-array/93089 "2023-01-17T12:55:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidschlegel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidschlegel/32/29711_2.png) [@davidschlegel](https://discourse.julialang.org/u/davidschlegel)\
**Post date:** [January 17, 2023, 12:55pm UTC](https://discourse.julialang.org/t/splatting-specific-dimension-of-multidimensional-array/93089/1 "2023-01-17T12:55:41Z")

</div>

Suppose, I have a multidimensional array. Can I somehow splat over a specific dimension?  
An example scenario would be the following:

```julia
arr = randn(2,2,3)
kron(arr...) # I would like to splat over the last dimension

```

However, here the splatting is performed regardless of the dimensions of the array and so the input is an NTuple of numbers.  
Is there any way to do this without resorting to converting to a one-dimensional array of matrices?

---

<div class="post-metadata">

**Author:** ![davidschlegel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/davidschlegel/32/29711_2.png) [@davidschlegel](https://discourse.julialang.org/u/davidschlegel)\
**Post date:** [January 17, 2023, 1:07pm UTC](https://discourse.julialang.org/t/splatting-specific-dimension-of-multidimensional-array/93089/2 "2023-01-17T13:07:15Z")

</div>

Actually, I figured it out myself.  
One way to do it is through array slicing by using `eachslice`. In the above example, one could do

```julia
kron(eachslice(arr, dims=3)...)

```

I don’t know about the efficiency of this though.

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [January 17, 2023, 2:49pm UTC](https://discourse.julialang.org/t/splatting-specific-dimension-of-multidimensional-array/93089/3 "2023-01-17T14:49:14Z")

</div>

> [@davidschlegel](#):
>
> `kron(eachslice(arr, dims=3)...)`

Using `reduce` should be better:

```julia
reduce(kron, eachslice(arr, dims=3))

```
