I have an NMatrix array like this
x = NMatrix.new([3, 2], [3, 5, 5, 1, 10, 2], dtype: :float64)
I want to divide each column by maximum value along the column.
Using numpy this is achieved like this
Y = np.array(([3,5], [5,1], [10,2]), dtype=float)
Y = Y / np.amax(Y, axis = 0)
But NMatrix throws this error when I try this
X = X / X.max
The left- and right-hand sides of the operation must have the same shape. (ArgumentError)
Edit
I'm trying to follow this tutorial. And to scale input, the tutorial divides each column by the maximum value in that column. My question is how to achieve that step using nmatrix.
My question is how to achieve the same with NMatrix.
Thanks!
A generic column-oriented approach:
> x = NMatrix.new([3, 2], [3, 5, 5, 1, 10, 2], dtype: :float64)
> x.each_column.with_index do |col,j|
m=col[0 .. (col.rows - 1)].max[0,0]
x[0 .. (x.rows - 1), j] /= m
end
> pp x
[
[0.3, 1.0] [0.5, 0.2] [1.0, 0.4] ]