Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mean Row of Matrix

Tags:

julia

I'm trying to use mean(A,1) to get the mean row of a matrix A, but am getting an error.

For example, try running the command mean(eye(3), 1).
This gives the error no method mean(Array{Float64,2},Int32).

The only documentation I can find for the mean function is here:
http://docs.julialang.org/en/release-0.1/stdlib/base/#statistics

mean(v[, region])

Compute the mean of whole array v, or optionally along the dimensions in region.

What is the region parameter?

EDIT: for Julia 0.7 and higher, write this as mean(v, dims=1).

like image 288
Timothy Shields Avatar asked Oct 15 '25 04:10

Timothy Shields


1 Answers

julia> using Statistics
julia> A = [[1 2 3];[ 4 5 6]]
2×3 Array{Int64,2}:
 1  2  3
 4  5  6

# Column means
julia> mean(A, dims=1)
1×3 Array{Float64,2}:
 2.5  3.5  4.5

# Row means
julia> mean(A, dims=2)
2×1 Array{Float64,2}:
 2.0
 5.0
like image 188
Timothée HENRY Avatar answered Oct 18 '25 01:10

Timothée HENRY