I have a 2D numpy array that looks like this,
[[3, 4, 5, 6], [4, 5, 6, 7], [9, 10, 3, 5]]
I converted this into a COO matrix using the following code:
# Flatten 2D array
data = np.asarray(twod_array).flatten()
row = np.arange(0, len(data))
col = np.arange(0, len(row))
# Make COO matrix
mat = coo_matrix((data, (row, col)), shape=(len(row), len(row)))
Is this the correct way of converting a 2D numpy array into a COO matrix?
EDIT
What I am trying to do is this, I have parts on one coloumn and item on the other.
parts item
processor, display, sensor temp. monitoring system
fan baldes, motor, sensor motion detecting fan
. .
. .
I have converted the data above to numbers so that they can be further processed.
parts items
1, 2, 3 1
4, 5, 3 2
So now, I want to feed the above data into LightFM, so I created a 2D array like this.
[[1, 2, 3, 1], [4, 5, 3, 2]]
But since LightFM's fit method only takes in np.float32 coo_matrix of shape [n_users, n_items] which is a matrix containing user-item interactions. I converted the 2D array using the above stated method.
mat.A
to check. What is your expected output? – Akavall