[Numpy-discussion] Proposal: Chaining np.dot with mdot helper function

Stefan Otte stefan.otte at gmail.com
Mon Feb 17 16:39:46 EST 2014

Hey guys,

I wrote myself a little helper function `mdot` which chains np.dot for
multiple arrays. So I can write

    mdot(A, B, C, D, E)

instead of these

    np.dot(np.dot(np.dot(np.dot(A, B), C), D), E)

I know you can use `numpy.matrix` to get nicer formulas. However, most
numpy/scipy function return arrays instead of numpy.matrix. Therefore,
sometimes you actually use array multiplication when you think you use
matrix multiplication. `mdot` is a simple way to avoid using
numpy.matrix but to improve the readability.

What do you think? Is this useful and worthy to integrate in numpy?

I already created an issuer for this:

jaimefrio also suggested to do some reordering of the arrays to
minimize computation:


More information about the NumPy-Discussion mailing list