A custom implementation of Numpy's Einsum function (Python)