I have the following numpy array:
import numpy as np pair_array = np.array([(205, 254), (205, 382), (254, 382), (18, 69), (205, 382), (31
If you are okay to add pandas as a dependency you can use this implementation
>>> import pandas as pd >>> df = pd.DataFrame(pair_array) >>> pd.crosstab(df[0], df[1]) 1 69 183 254 267 382 0 18 1 0 0 0 0 31 0 1 0 1 1 183 0 0 0 1 1 205 0 0 1 0 2 254 0 0 0 0 1