Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Try multiply(M.col(i), 1.0/(sum(M.col(i))(0)), M.col(i));

This takes the column, finds the sum, and multiplies the column by 1/sum. Then use the reduce to check.

Try multiply(M.col(i), 1.0/(sum(M.col(i))(0)), M.col(i));

This takes the column, finds the sum, and multiplies the column by 1/sum. Then use the reduce to check.

If you want to use the normalize function, you need to change the norm type to NORM_L1, and it will do the same thing. Actually, just do this, that's better.

Try multiply(M.col(i), 1.0/(sum(M.col(i))(0)), M.col(i));

This takes the column, finds the sum, and multiplies the column by 1/sum. Then use the reduce to check.

If you want to use the normalize function, you need to change the norm type to NORM_L1, and it will do the same thing. Actually, just do this, that's better.better. Here's the documentation on the normalize function so you can see why NORM_L2 wasn't working and why NORM_L1 will.