ashley
ashley

Reputation: 1565

More elegant way of finding the mean of the rows in a matrix with julia

I have a 3x55 matrix of ints. I want to center each row around its mean. This gets the right answer, but it's ugly:

row_mean = mean(points,[2])
points[1,:] = points[1,:] - row_mean[1]
points[2,:] = points[2,:] - row_mean[2]
points[3,:] = points[3,:] - row_mean[3]

Any ideas?

Upvotes: 1

Views: 508

Answers (1)

Reza Afzalan
Reza Afzalan

Reputation: 5756

EDITED:

You can use the element-wise minus function, .-, to calculate the difference between each row and its mean value:

points .- mean(points, 2)

Upvotes: 4

Related Questions