# Pipe operator with multiple instances

**URL:** https://discourse.julialang.org/t/pipe-operator-with-multiple-instances/51505
**Category:** General Usage
**Tags:** question
**Created:** [December 9, 2020, 8:52am UTC](https://discourse.julialang.org/t/pipe-operator-with-multiple-instances/51505 "2020-12-09T08:52:17Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kadir-gunel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kadir-gunel/32/35790_2.png) [@kadir-gunel](https://discourse.julialang.org/u/kadir-gunel)
#### Post date: [December 9, 2020, 8:52am UTC](https://discourse.julialang.org/t/pipe-operator-with-multiple-instances/51505/1 "2020-12-09T08:52:17Z")

</div>

I have a function which takes a Matrix as an argument. And I have a multidimensional array as input (513, 321, 1, 2). The last column represents the number of samples. All I want is to use the `|>` pipe operator for each sample.

I tried to reshape the input to (513, 321, 2) then use pipe operator and use broadcasting with the intended function. But the broadcast in this case works for each element.

Is there any way to do this?

B.R.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [December 9, 2020, 9:00am UTC](https://discourse.julialang.org/t/pipe-operator-with-multiple-instances/51505/2 "2020-12-09T09:00:25Z")

</div>

broadcasting always works for each element in a container, it can’t know that you think of the last dimension as the “sample” dimension. But with `eachslice` you can make an iterator out of your array that has the desired property:

```julia
julia> data = rand(513, 321, 1, 2)

julia> eachslice(data, dims = 4) .|> size

2-element Vector{Tuple{Int64, Int64, Int64}}:
 (513, 321, 1)
 (513, 321, 1)
```
