Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Julia: Vectorize function along a specific axis of a matrix

What is the best way in Julia to vectorize a function along a specific axis? For example sum up all the rows of a matrix. Is it possible with the dot notation?

sum.(ones(4,4))

Does not yield the desired result.

like image 648
bonfab Avatar asked Dec 22 '22 14:12

bonfab


1 Answers

Try using the dims argument on a lot of functions that deal with sets of values.

sum([1 2; 3 4], dims=2)
2×1 Matrix{Int64}:
 3
 7

# or
using Statistics

mean([1 2; 3 4], dims=1)
1×2 Matrix{Float64}:
 2.0  3.0
like image 127
Andre Wildberg Avatar answered Feb 20 '23 15:02

Andre Wildberg