For Programmers: Free Programming Magazines  


Home > Archive > APL > April 2007 > indexing









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author indexing
LanceMD@gmail.com

2007-02-27, 6:57 pm

I have a Matrix M. Let's say it's shape is 8 8
I want all elements in a particular row combined with all elements
from a particular column. Lets say V{<--}2 5. That is the third row
and sixth column (quadIO is 0)

So my code looks like

M[V[0] ; ],M[ ; V[1]]

Is there a way of doing this referring to M only once?

For example:

,M[code]

I'm using APL+Win 2.0

Thanks,
Lance

Ted Edwards

2007-02-27, 6:57 pm

LanceMD@gmail.com wrote:
> I have a Matrix M. Let's say it's shape is 8 8
> I want all elements in a particular row combined with all elements
> from a particular column. Lets say V{<--}2 5. That is the third row
> and sixth column (quadIO is 0)
>
> So my code looks like
>
> M[V[0] ; ],M[ ; V[1]]
>
> Is there a way of doing this referring to M only once?


Why do you care? I'm using APL2 on a ThinkPad T23
and
'TIMER' 'ToASCII' need 'tutil' 'charset'
{quad}IO{is}0
M{is}r{rho}{iota}{times}/r{is}10 20
1000 TIMER'{rho}M[V[0];],M[;V[1]]'
0.000036
M{is}r{rho}{iota}{times}/r{is}1000 2000
1000 TIMER'{rho}M[V[0];],M[;V[1]]'
0.000475
M{is}0.1{times}?(r{is}10 20){rho}1000
1000 TIMER'{rho}M[V[0];],M[;V[1]]'
0.000037
M{is}0.1{times}?(r{is}1000 2000){rho}1000
1000 TIMER'{rho}M[V[0];],M[;V[1]]'
0.000566

That last is half a millisecond for a random two million element
floating point array. (TIMER did it 1000 times and divided the result by
1000.)

Ted
Ibeam2000

2007-02-27, 6:57 pm

It depends on what you really mean by "referring to". You need to get
the shape of M in order to construct the indices to make (,M)[code]
work.

Something like

(,M)[ (rho M) encode (V[0],[-0.5] iota 1 drop rho M),(iota 1 take rho
M),[-0.5] V[1] ]

[]io must be zero.

This code fragment should work on nearly all APL versions known to
man.

graham

2007-02-27, 6:57 pm


<LanceMD@gmail.com> wrote in message
news:1172594281.164464.102030@t69g2000cwt.googlegroups.com...
>I have a Matrix M. Let's say it's shape is 8 8
> I want all elements in a particular row combined with all elements
> from a particular column. Lets say V{<--}2 5. That is the third row
> and sixth column (quadIO is 0)


> Is there a way of doing this referring to M only once?
> For example:
>
> ,M[code]
> Lance


I agree with the other responses you have had about why would you want to do
it and what you mean by referring to M only once. If you already know the
shape of M and it is fixed then yes the code in index origin 1 is simply:

(,M)[(({iota}8)+8×R-1),C+8×0,{iota}7]

where R is the row you want and C the column.

Graham.


Seth Breidbart

2007-03-28, 7:58 am

In article <Fo_Eh.648$Xi2.491@edtnps89>,
Ted Edwards <Ted_Espamless@telus.net> wrote:
>LanceMD@gmail.com wrote:
>
>Why do you care?


Maybe M is computed and he doesn't want to store it.

Seth
Ermosterter9

2007-04-28, 1:53 pm

Martha Stewart in anal action!
http://Martha-Stewart-anal-action.o...hp?movie=726071
yashchi

2007-04-29, 1:41 pm

quote:
Originally posted by graham
<LanceMD@gmail.com> wrote in message
news:1172594281.164464.102030@t69g2000cwt.googlegroups.com...
>I have a Matrix M. Let's say it's shape is 8 8
> I want all elements in a particular row combined with all elements
> from a particular column. Lets say V{<--}2 5. That is the third row
> and sixth column (quadIO is 0)


> Is there a way of doing this referring to M only once?
> For example:
>
> ,M[code]
> Lance


I agree with the other responses you have had about why would you want to do
it and what you mean by referring to M only once. If you already know the
shape of M and it is fixed then yes the code in index origin 1 is simply:

(,M)[(({iota}8)+8×R-1),C+8×0,{iota}7]

where R is the row you want and C the column.

Graham.



There is another way to achieve this goal (scatter indexing) for APL2:

(R ({iota}8))(({iota}8) C){Index} {Each} {Enclose} M

see Brown, Pakin and Polivka "APL2 at a glance", p.396.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com