I have the first matrix which should account for each users (in lines) which products (in columns) they like.
Let’s take 3 users and 5 products.
No user liked a product, so my matrix ILike equals a nul matrix :
let matrixILike = [[0.; 1.;2.;3.]
[1.;0.;0.;0.]
[2.;0.;0.;0.]
[3.;0.;0.;0.]
[4.;0.;0.;0.]
[5.;0.;0.;0.]]
Now user 1 likes product 2 and user 3 likes product 5 which can be summarized in the following matrix:
let matrixAction = [[1.;2.]
[3.;5.]]
So I would like to implement the matrix ILike thanks to the matrixAction to obtain a new updated matrixILike like this :
let matrixILike = [[0.; 1.;2.;3.]
[1.;0.;0.;0.]
[2.;1.;0.;0.]
[3.;0.;0.;0.]
[4.;0.;0.;0.]
[5.;0.;0.;1.]]
I try to do this with a “match with” code but it is not working.
for k = 0 to matrixAction.NumRows - 1 do
match (matrixAction.[k,0] , matrixAction.[k,1]) with
| (matrixILike.[x,0] , matrixILike.[0,y]) -> (matrixILike.[x,y] <- 1.)
| _ -> (matrixILike.[x,y] <- 0.)
matrixILike
If you have any suggestions I take it.
Without changing your input parameters, this function will do the job.
Usage:
It uses List.mapi which is the same as List.map but with additional parameter: the index.