[Numpy-discussion] array of matrices

Geoffrey Irving irving@naml...
Sat Mar 28 11:47:32 CDT 2009


On Sat, Mar 28, 2009 at 12:47 AM, Robert Kern <robert.kern@gmail.com> wrote:
> 2009/3/27 Charles R Harris <charlesr.harris@gmail.com>:
>>
>> On Fri, Mar 27, 2009 at 4:43 PM, Robert Kern <robert.kern@gmail.com> wrote:
>>>
>>> On Fri, Mar 27, 2009 at 17:38, Bryan Cole <bryan@cole.uklinux.net> wrote:
>>> > I have a number of arrays of shape (N,4,4). I need to perform a
>>> > vectorised matrix-multiplication between pairs of them I.e.
>>> > matrix-multiplication rules for the last two dimensions, usual
>>> > element-wise rule for the 1st dimension (of length N).
>>> >
>>> > (How) is this possible with numpy?
>>>
>>> dot(a,b) was specifically designed for this use case.
>>
>> I think maybe he wants to treat them as stacked matrices.
>
> Oh, right. Sorry. dot(a, b) works when a is (N, 4, 4) and b is just
> (4, 4). Never mind.

It'd be great if this operation existed as a primitive.  What do you
think would be the best way in which to add it?  One option would be
to add a keyword argument to "dot" giving a set of axes to map over.
E.g.,

    dot(a, b, map=0) = array([dot(u,v) for u,v in zip(a,b)]) # but in C

"map" isn't a very good name for the argument, though.

Geoffrey


More information about the Numpy-discussion mailing list