Arslán Arslán - 1 year ago 91
Python Question

Changing range of numbers in Python

I am doing SVD in Python, the range of my data index is 150,000 to 160,000. Because of this SVD is getting very resource intensive. How can I change the range of this data to 0-10,000 while maintaining duplicates.

Eg: i have consecutive data points :150001,150001,155003,156004,157005

it should map to :1,1,2,3,4

Such that the range shrinks, and i dont have to hand a higly sparse data martrix.

Answer Source

The following code records the indices of the unique numbers in the list of numbers in rank order:

>>> import numpy as np
>>> v = [169,169,256,945,945,945,345,9999]
>>> np.hstack([0, np.cumsum(np.diff(v)!=0)])
array([0, 0, 1, 2, 2, 2, 3, 4])

Please update the question to reflect these requirements.