[Numpy-discussion] proposing a "beware of [as]matrix()" warning
Wed Apr 28 16:28:51 CDT 2010
On Wed, Apr 28, 2010 at 2:12 PM, Alan G Isaac <email@example.com> wrote:
> On 4/28/2010 12:05 PM, Travis Oliphant wrote:
>> A proposal was made to allow "calling a NumPy array" to infer dot
>> a(b) is equivalent to dot(a,b)
>> a(b)(c) would be equivalent to dot(dot(a,b),c)
> Here is a related ticket that proposes a more
> explicit alternative: adding a ``dot`` method
> to ndarray.
FWIW, I have borrowed a convenience function chain_dot originally from
pandas that works for me as a stop gap for more readable code.
Returns the dot product of the given matrices.
arrs: argument list of ndarrays
Dot product of all arguments.
>>> import numpy as np
>>> from scikits.statsmodels.tools import chain_dot
>>> A = np.arange(1,13).reshape(3,4)
>>> B = np.arange(3,15).reshape(4,3)
>>> C = np.arange(5,8).reshape(3,1)
return reduce(lambda x, y: np.dot(y, x), arrs[::-1])
More information about the NumPy-Discussion