'Fast custom matrix multiplication

I have matrices in Python (numpy array) and want to multiply two matrices, but not by regular matrix multiplication, but in path algebra, i.e.

If A is a n×n matrix and B is a n×n matrix (non-sparse), and C is the resulting n×n matrix, then

C[i,j] = min(A[i,k] + B[k,j] for k = 0,...,n-1).

The problem I have is that I am dealing with very big matrices, so a regular (triple) loop in Python is not the fastest way. Is there a way (perhaps combining with in C/C++) that can optimize such repetative computations faster?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source