Currently, I have a list of tuples that looks like this:
[(0, 0.13), (323, 0.72), (812, 0.35), ..., (2127, 0.44)]
The tuples are ordered by their first element: 0 -> 323 -> 812 -> ...
I want to turn this list of tuples into an array (or a sparse matrx), with the first element of each tuple being the second element's array index:
[0.13, 0, ..., 0, 0.72, 0, ..., 0, 0.35, 0, ...]
And to fill the end of this array with 0s to extend it into a certain length.
Can anyone provide a fast implementation of the function above in python?
I currently use a dictionary to accomplish this procedure, and it's very slow for large arrays.
Thank you.