[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tensor product question
From: |
Jordi Gutiérrez Hermoso |
Subject: |
Re: Tensor product question |
Date: |
Wed, 15 May 2013 10:39:41 -0400 |
On 15 May 2013 05:05, JFCardoso <address@hidden> wrote:
> I find Jordi's proposal a bit mysterious.
It's just broadcasting:
http://www.gnu.org/software/octave/doc/interpreter/Broadcasting.html
> Here is an alternate version which looks more transparent, at least
> to me.
> function out = vector_tensor_product (varargin)
> n = length (varargin);
> dims = zeros(n,1) ;
>
> out = varargin{1}(:);
> dims(1) = length(out) ;
>
> for i = 2:n
> dims(i) = length(varargin{i})
> out = out(:) * varargin{i}(:)' ;
> endfor
>
> out = reshape(out, dims) ;
> endfunction
Sure that works too. You're using broadcasting too, in a way. Ordinary
matrix multiplication of a column vector times a row vector
corresponds to broadcasting. Since Octave 3.6, a(:)*b(:)' is the same
as a(:).*b(:)'
- Jordi G. H.