[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: some multi-dimensional matrix problem
From: |
Bart Vandewoestyne |
Subject: |
Re: some multi-dimensional matrix problem |
Date: |
Wed, 26 May 2004 02:53:13 -0500 |
User-agent: |
Mutt/1.3.28i |
On Tue, May 25, 2004 at 04:03:37PM +0200, David Bateman wrote:
>
> All the functions squeeze and reshape do is change the dim_vector for
> the octave_value, without touching the underlying data which is stored
> essentially as a vector. So there is no transpose involved, and it is
> thus a low cost operation. If what you want is the transpose of this
> then you have no choice you must touch the underlying data, thus
> "transpose(squeeze(x))" is probably optimal.
Thanks for the tips, but still, my problem was not solved and it was
because of one exceptional case. Let me explain a bit more...
I have M s-dimensional pointsets of length N, which i represent in a
multidimensional sxNxM matrix:
p = rand(s, N, M);
Now I want to evaluate these M pointsets for certain functions. To
make things easy, suppose the function evaluation for an s-dimensional
pointset of length N is just taking the product along the dimension s for
each of the N points:
myprod = prod(p, 1);
As a result, i would like to have an MxN matrix, representing in each
row the function evaluated at N s-dimensional points.
Therefore, I THOUGHT could do:
transpose(squeeze(myprod));
But there was one exceptional case which gave me wrong output,
being the case when I only use 1 point (N=1), then I got my results as
1xM where i expected Mx1.
After some more experimenting, i *think* I've found that
transpose(reshape(myprod, N, M))
does what I want. If i now enter a sx1xM dimensional pointset, i do get
my result as an Mx1 matrix.
I guess this is the best way to solve my 'problem', and i cannot avoid
taking the transpose? Or does anybody see any better ways of doing
this?
The test-script i used is:
%%%%%%%%%%%%%%%%%%%%%%%%%%% BEGIN SCRIPT %%%%%%%%%%%%%%%%%%%%%%%%%
function squeeze_test(s, N, M)
% Create M s-dimensional pointsets with each N points.
p = rand(s, N, M);
% Calculate the N function values at each of these M pointsets
myprod = prod(p, 1)
% Show the result as a MxN matrix.
% This goes wrong when N=1...
transpose(squeeze(myprod))
% This seems correct when N=1
transpose(reshape(myprod, N, M))
%%%%%%%%%%%%%%%%%%%%%%%%%%%%% END SCRIPT %%%%%%%%%%%%%%%%%%%%%%%%%%
Regards,
Bart
--
!!!!!!!!!!!!!!!!!!! email change !!!!!!!!!!!!!!!!!!!!
My email address is now address@hidden
Please update your addressbook!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.
Octave's home on the web: http://www.octave.org
How to fund new projects: http://www.octave.org/funding.html
Subscription information: http://www.octave.org/archive.html
-------------------------------------------------------------