Closed
Description
I wrote myself a little helper function tat I constantly use. The function chains calls of dot
which makes long matrix multiplication much more readable. I call the function mdot
for "multiple dot".
M = np.eye(5)
# instead of this
print M.dot(M).dot(M).dot(M).dot(M)
# or this
print np.dot(np.dot(np.dot(np.dot(M, M), M), M), M)
# I can write this
print mdot(M, M, M, M, M)
This is the implementation:
def mdot(*args):
return reduce(np.dot, args)
This is a really simple function but it helps me tremendously. Are you interested in integrating something like this?