qwebfub3i4u
qwebfub3i4u

Reputation: 319

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

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?

Upvotes: 3

Views: 2609

Answers (1)

Cory Kramer
Cory Kramer

Reputation: 117856

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.

Upvotes: 6

Related Questions