. 10 range(50)^3 100 , (@Primusa's):
, 0 - 50^3 - 1 . ( , A .) np.ravel_multi_index np.unravel_index .
B , , np.bincount. , 50x50x50, . ( 0 49, len(A) 125000):
>>> B = np.random.randint(0, 50, (10000000, 3))
>>> Br = np.ravel_multi_index(B.T, (50, 50, 50))
>>> result = np.bincount(Br, minlength=125000).reshape(50, 50, 50)
:
>>> B = np.random.randint(0, 3, (10, 3))
>>> Br = np.ravel_multi_index(B.T, (3, 3, 3))
>>> result = np.bincount(Br, minlength=27).reshape(3, 3, 3)
>>>
>>> B
array([[1, 1, 2],
[2, 1, 2],
[2, 0, 0],
[2, 1, 0],
[2, 0, 2],
[0, 0, 2],
[0, 0, 2],
[0, 2, 2],
[2, 0, 0],
[0, 2, 0]])
>>> result
array([[[0, 0, 2],
[0, 0, 0],
[1, 0, 1]],
[[0, 0, 0],
[0, 0, 1],
[0, 0, 0]],
[[2, 0, 1],
[1, 0, 1],
[0, 0, 0]]])
, , [2,1,0] B,
>>> result[2,1,0]
1
As stated above: To convert indexes to Aand actual strings A(which are indexes to my result), you can use np.ravel_multi_indexand np.unravel_index. Or you can leave the last change (i.e. Use result = np.bincount(Br, minlength=125000), then the counts are indexed exactly the same as A.