[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
A.dot(B).dot(C).dot(D).dot(E)
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:
https://github.com/numpy/numpy/issues/4311
jaimefrio also suggested to do some reordering of the arrays to
minimize computation:
https://github.com/numpy/numpy/issues/4311#issuecomment-35295857
Best,
Stefan
More information about the NumPy-Discussion
mailing list