Skip to content Skip to sidebar Skip to footer

Array Reclassification With Numpy

I have a large (50000 x 50000) 64-bit integer NumPy array containing 10-digit numbers. There are about 250,000 unique numbers in the array. I have a second reclassification table

Solution 1:

Store the lookup table as a 250,000 element array where for each index you have the mapped value. For example, if you have something like:

lookups = [(old_value_1, new_value_1), (old_value_2, new_value_2), ...]

Then you can do:

idx, val = np.asarray(lookups).T
lookup_array = np.zeros(idx.max() + 1)
lookup_array[idx] = val

When you get that, you can get your transformed array simply as:

new_array = lookup_array[old_array]

Post a Comment for "Array Reclassification With Numpy"