Suppose I have an array that stores a total of 800,000 integers of type 'int8'. I want to compare every pair of numbers in the array, and the result should be 1 if the numbers in those two positions are equal, and 0 if the numbers in those two positions are not equal. The results should be stored in an array of size (800000,800000) of type 'int8'. What are some efficient ways to compute this while optimizing speed and minimizing memory usage?
Ex.
array = [52, 41, 62 , 52]
result
[1,0,0,1
0,1,0,0
0,0,1,0
1,0,0,1]
array = np.array([52, 41, 62 , 52]) ; (array[:, None] == array).astype(int)The results should be stored in an array of size (800000,800000) of type 'int8'This will take 640 GB, assuming one byte per array element.