I have a data structure like this:
- my source arrays are a sorted arrays like
[2,3,4,5,7,8,9,10,11] - I know a priori the max number of this array collection, in this case it’s 17
What I need to do is to build a sparse matrix with 17 rows (the max number mentioned above) and n cols where n is the number of arrays, and each column vector should contain a mapping of the index+1 of the source vector in position [value of the source vector’s element], and 0 when it’s not present. In the mentioned example the output vector should be [0,1,2,3,4,0,5,6,7,8,9,10,11,0,0,0,0].
Is there an efficient way to do that in numpy without having to loop through cols and rows which would have a dramatic computational cost?
machine-learningorscikit-learnquestion, kindly do not spam irrelevant tags (removed & replaced withscipy). That said, have a look here: Creating a sparse matrix from numpy arrayscipy. Is that because you want to usescipy.sparse? Or are you just usingsparsein the loose sense of an array with some 0s?scipytag was added by me in en edit, not by OP, as clearly stated in my 1st comment above