Why is `sum` on the Matrix return matrix and not Vector?

If i do

mat = rand(8,8)
sum(mat, 1)

the return type is a single row matrix, while it sum(mat, 2)gives a single column matrix. This surprises me, since the size of a singleton is usually reduced by 0.5, so I expect that the return type of both operations will be a Vector. Why is the size of the singleton not discarded here?

I could expect that this would be to preserve orientation (for example, sum(mat, 1)this is a row vector), but the behavior is the same at 0.6, which has explicit 1-d RowVectors, so this does not seem to explain.

Thank!

+4
source share
1 answer

, , sum, . , . , , , ./:

julia> A = rand(1:100, 4, 3)
4×3 Array{Int64,2}:
 94  50  32
 46  15  78
 34  29  41
 79  22  58

julia> A ./ sum(A, 1)
4×3 Array{Float64,2}:
 0.371542  0.431034  0.15311
 0.181818  0.12931   0.373206
 0.134387  0.25      0.196172
 0.312253  0.189655  0.277512

RowVector s, .

, , . .

+4

Source: https://habr.com/ru/post/1670330/


All Articles