Here are two ways:
julia> a = [ [[8, 13, 1]] [[12, 4, 9]] [[13, 18, 7]]
[[3, 19, 20]] [[8, 3, 11]] [[10, 9, 12]] ] # as in original question
2×3 Matrix{Vector{Int64}}:
[8, 13, 1] [12, 4, 9] [13, 18, 7]
[3, 19, 20] [8, 3, 11] [10, 9, 12]
julia> [maximum.(b) for b in eachrow(a)] # answer above
2-element Vector{Vector{Int64}}:
[13, 12, 18]
[20, 11, 12]
julia> map(eachrow(a)) do row # desired result
max.(row...)
end
2-element Vector{Vector{Int64}}:
[13, 18, 9]
[10, 19, 20]
julia> using TensorCast
julia> @reduce _[i][k] := maximum(j) a[i,j][k]
2-element Vector{SubArray{Int64, 1, Matrix{Int64}, Tuple{Base.Slice{Base.OneTo{Int64}}, Int64}, true}}:
[13, 18, 9]
[10, 19, 20]
But note that it’s normally easier to work with one 3D-array, instead of arrays of arrays. (This is what @reduce
is doing, it concatenates, takes maximum(tmp, dims = 3)
, then slices again.)