help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Vector approach to row margin frequencies


From: Jaroslav Hajek
Subject: Re: Vector approach to row margin frequencies
Date: Thu, 25 Jun 2009 06:25:41 +0200

On Wed, Jun 24, 2009 at 7:17 PM, Judd Storrs<address@hidden> wrote:
> On Wed, Jun 24, 2009 at 10:56 AM, Jaroslav Hajek <address@hidden> wrote:
>>
>> On Wed, Jun 24, 2009 at 4:48 PM, ws<address@hidden> wrote:
>> >> In 3.2.0, the fastest way is also the most obvious (from math point of
>> >> view):
>> >>
>> >> F = X / diag (S)
>> >>
>> >> In 3.0.x, take any of the bsxfun or repmat workarounds (or just use
>> >> the above and upgrade to 3.2 soon)
>> >
>> > Well ....
>> >
>> > octave:7> version
>> > ans = 3.2.0
>> > octave:8> X/diag(S)
>> > error: operator /: nonconformant arguments (op1 is 16x3, op2 is 16x16)
>> >
>> > I will play with the bsxfun thing, though, just to understand it...
>> >
>> > Thanks!
>>
>> Oh yes, sorry, I confused rows and columns. diag(S) \ X
>
> Nah, you just didn't specifiy what S was ;) Depending on whether S is
> sum(X,1) or sum(X,2) you need one of the following:
>
> X / diag(sum(S,1))
> diag(sum(S,2)) \ X
>
> The diag() stuff is really cool. Now I'll have to look into whether
> reshape+diag+reshape is faster than bsxfun for 3D arrays. Thanks Jaroslav!
>

Surely is, because reshape is an O(1) operation (shares data, only
changes their interpretation). However, reshape/diag/reshape is only
sufficient if you want to scale the leading/trailing dimension of a
N-d array. If you need to scale a dimension in the middle (which is
uncommon, but can happen), you can use permute it to move it to the
end (or beginning, but end is better), or just turn again to repmat or
bsxfun.


-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]