[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: n-dim product
From: |
Francesco Potorti` |
Subject: |
Re: n-dim product |
Date: |
Wed, 30 Jul 2008 16:55:01 +0200 |
>> If I have two vectors and want to produce a matrix of all the possible
>> products of their elements, I just multiply them:
>>
>> octave> x=1:3; y=1:4; x'*y
>> ans =
>>
>> 1 2 3 4
>> 2 4 6 8
>> 3 6 9 12
>>
>> How to generalise this simple operation to multiple dimensions?
>
>the easy way:
>
>[xx, yy, zz] = ndgrid (x, y, z);
>xx .* yy .* zz
>
>this may be faster:
>reshape ((x'*y)(:) * z, [length(x), length(y), length(z)])
>
>(x, y, z are row vectors)
Thank you!
--
Francesco Potortì (ricercatore) Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR Fax: +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa Email: address@hidden
(entrance 20, 1st floor, room C71) Web: http://fly.isti.cnr.it/