Partitioning a matrix in batches

I think you want push! not append!, but note that result = Array{Array{Float32,2},1} is a type, result = Array{Array{Float32,2},1}() is an empty vector (although still has different eltype).

But you can also do this:

[matrix[:, i:min(i+batchsize-1,size(matrix,2))] for i in 1:batchsize:size(matrix,2)]

or this

map(Iterators.partition(axes(matrix,2), batchsize)) do cols
    matrix[:, cols]
end
1 Like