To illustrate the problem I am facing, here is some example code:
a = np.round(np.random.rand(10, 15))
counta = np.count_nonzero(a, axis=-1)
print(counta)
A = np.einsum('im,mj->ijm', a, a.T)
countA = np.count_nonzero(A, axis=-1)
print(countA)
It creates a 2D array and counts its nonzero elements along the last axis. Then it creates a 3D array, of which the nonzero elements are again counted along the last axis.
My problem is that my array a is so large, that I can perform the first step, but not the second step, since the A array would take up too much memory.
Is there any way to still get countA? That is to count the zeros in A along a given axis without actually creating the array?