Calculating the covariance requires two sequences of data points. Either from two vectors or between the columns of a matrix. The mean is different as it requires one sequence. What did you expect to get from the covariance function of a vector? The variance?
2015-05-08 16:01 GMT-04:00 JPi <[email protected]>: > Hello, > > 1. I can apply mean to an array of vectors, but doing the same for cov > produces an error. > > 2. I can apply cov to a matrix, which produces the covariance matrix > treating each row as an observation. Applying mean to the same matrix > produces a scalar average of all elements in the matrix. > > This asymmetric treatment is counter-intuitive. What is the rationale? > > Thanks! > > n=10 > A=Array(Vector,n) > > for i=1:n > A[i]=randn(3) > end > > println(mean(A)) > println(cov(A)) # > produces an error > > B=Array(Float64,n,3) > for i=1:n > B[i,:]=A[i] > end > > println("mean:",mean(B)) # > produces average of all elements in B > println("covariance matrix:",cov(B)) # > produces covariance matrix of columns of B > > > >
