Julia: How do I sum the elements of a matrix together?

Viewed 842

I have a matrix C of type Matrix{Float64} with 20x10 elements.

I need to sum the 10 elements to get a vector of size 20x1 (or 1x20).

How would I go about doing this?

1 Answers

You can use sum() and specify the dimension :

sum(A, dims=2)

where A is your Matrix. In this case 1 would sum along columns and 2 would sum along rows.

Related