[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Broadcasting equivalent for multiplication?
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: Broadcasting equivalent for multiplication? |
Date: |
Wed, 1 May 2013 16:04:01 -0400 |
On 1 May 2013 15:57, Jordi Gutiérrez Hermoso <address@hidden> wrote:
> On 1 May 2013 15:37, Nir Krakauer <address@hidden> wrote:
>> I have an n*m array X and an n*k array Y. Is there a shortcut to get
>> an n*m*k array Z such that
>>
>> Z(:, i, j) is equal to X(:, i) .* Y(:, j) ?
>
> So you want a 3d multiplication table? Does this work?
>
> X = rand (3, 5); Y = rand (3, 7);
> Z = X.*permute (Y, [1,3,2]);
Oh, a remark, since I've fallen prey to this at least twice: if you
just do W = squeeze (sum (Z)), this is just ordinary matrix
multiplication W =X'*Y. Make sure you're not slowly reimplementing
matrix multiplication!
http://jordi.platinum.linux.pl/piccies/bcast-ApTimesBp.png
- Jordi G. H.