[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Tensor product question
From: |
JFCardoso |
Subject: |
Re: Tensor product question |
Date: |
Wed, 15 May 2013 02:05:38 -0700 (PDT) |
I find Jordi's proposal a bit mysterious.
Here is an alternate version which
looks more transparent, at least to me.
Cheers, JF
###########################################
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
###########################################
On 14 May 2013 16:11, Nir Krakauer <address@hidden> wrote:
> Given d vectors v_1, v_2, v_3, v_4, ..., is there a general way to get
> the d-dimensional tensor product
>
> A(i, j, k, l,...) = v_1(i) * v_2(j) * v_3(k) * v_4(l) * ...
This is kinda ugly, but...
function out = vector_tensor_product (varargin)
n = length (varargin);
p = 1:n;
out = varargin{1}(:);
for i = 2:n
pp = p;
pp([1,i]) = pp([i,1]);
out = out .* permute (varargin{i}(:), pp);
endfor
endfunction
--
View this message in context:
http://octave.1599824.n4.nabble.com/Tensor-product-question-tp4652922p4652943.html
Sent from the Octave - General mailing list archive at Nabble.com.