Pipe operator with multiple instances

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.

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> 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)
3 Likes