how to apply func[x;y;z] to each row of a 3-column table

hi, gurus

?

imaging that i have a table as follows:

a

1 2 3

4 5 6

3 4 5

6 7 8

2 3 5

how to apply a function func[x;y;z] to each row of this table, so that? for each row, the item in?the first column is x, the item in the second column is y and the item in the 3rd column is z ?

?

any idea?

?

Thanks!


CHEN, Cheng

Try this:

{x+y+z}  .  a: 3 cut til 9

Am 17.03.2012 16:02, schrieb CHEN, Cheng:

hi, gurus

 

imaging that i have a table as follows:

a

1 2 3

4 5 6

3 4 5

6 7 8

2 3 5

how to apply a function func[x;y;z] to each row of this table, so that  for each row, the item in the first column is x, the item in the second column is y and the item in the 3rd column is z ?

 

any idea?

 

Thanks!


CHEN, Cheng


You received this message because you are subscribed to the Google Groups “Kdb+ Personal Developers” group.
To post to this group, send email to personal-kdbplus@googlegroups.com.
To unsubscribe from this group, send email to personal-kdbplus+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/personal-kdbplus?hl=en.

hum, not working :-)

?

'rank error

?

anyway, thanks for your help

Kim was only missing the each right

in case it works as + is an atomic function

and a was 3 by 3

q)a: 3 cut til 15

q)func:{x+y+z}

q)func ./:a

3 12 21 30 39

Cheers,

  Attlia

haha, it works!

?

thanks a lot Attila!

(f’) . a

=CEn data de 17 martie 2012, 17:02, CHEN, Cheng a scr=
is:
> hi, gurus
>
> imaging that i have a table as follows:
> a
> 1 2 3
> 4 5 6
> 3 4 5
> 6 7 8
> 2 3 5
>
> how to apply a function func[x;y;z] to each row of this table, so that=A0=
for
> each row, the item in=A0the first column is x, the item in the second col=
umn
> is y and the item in the 3rd column is z ?
>
> any idea?
>
> Thanks!
>
> –
> CHEN, Cheng
>
> –
>

Submitted via Google Groups

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1257)

that would need a flip
(f’) . flip a

Cheers,
Attila
On 17 Mar 2012, at 19:53, Felix LUNGU wrote:

> (f’) . a
>
> =CEn data de 17 martie 2012, 17:02, CHEN, Cheng =
a scris:
>> hi, gurus
>>
>> imaging that i have a table as follows:
>> a
>> 1 2 3
>> 4 5 6
>> 3 4 5
>> 6 7 8
>> 2 3 5
>>
>> how to apply a function func[x;y;z] to each row of this table, so =
that for
>> each row, the item in the first column is x, the item in the second =
column
>> is y and the item in the 3rd column is z ?
>>
>> any idea?
>>
>> Thanks!
>>
>> –
>> CHEN, Cheng
>>
>> –
>> You received this message because you are subscribed to the Google =
Groups
>> “Kdb+ Personal Developers” group.
>> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
>> To unsubscribe from this group, send email to
>> personal-kdbplus+unsubscribe@googlegroups.com.
>> For more options, visit this group at
>> http://groups.google.com/group/personal-kdbplus?hl=en.
>
> –
> You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
> To unsubscribe from this group, send email to =
personal-kdbplus+unsubscribe@googlegroups.com.
> For more options, visit this group at =
http://groups.google.com/group/personal-kdbplus?hl=en.
>


actually, it works even without ’

f . flip a

?

however, this implmentation takes the first column as x, 2n as y, 3rd as z, and then do x+y+z. This is no longer a row-by-row processing.

Am 17.03.2012 20:30, schrieb Attila Vrabecz:

Kim was only missing the each right

I should have read the question more thoroughly. :-)

in case it works as + is an atomic function

and a was 3 by 3

q)a: 3 cut til 15

q)func:{x+y+z}

q)func ./:a

3 12 21 30 39

Cheers,

  Attlia

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1257)

nope. the formatting of the sample is bad. a is not a table but a =
matrix.

for the first iteration x y z is 1 2 3.
q)a:(1 2 3)+:3*til 5
q)a
1 4 7 10 13
2 5 8 11 14
3 6 9 12 15
q)f:{x,y,z}
q)(f’). a
1 2 3
4 5 6
7 8 9
10 11 12
13 14 15

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1257)

nope, the OP originally said
> imaging that i have a table as follows:
> a
> 1 2 3
> 4 5 6
> 3 4 5
> 6 7 8
> 2 3 5

so he has a list of rows
not a list of columns

however you are of course right
if he were to have “a” the other way around
that would be the way to compute it
and it is actually good idea for performance reasons

Cheers,
Attila

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1257)

then

(f.)'a

To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1257)

nope, close, but not quite

  1. space is needed between f and .
    or one can use .[f]
  2. monad’a is k, in q one has to say
    m’[a] or (m’) or m each a
  3. even if we use corrent syntax in (1.)
    it is not ideal as both these create a projection
    which is obviously slower than direct application

q)\t do[10000;(f .)each a]
150

q)\t do[10000;f ./:a]
120

So if you want me to elaborate on why I chose to suggest
f ./:a

because it is
short, fast and simplest (no parentheses)

in all fairness
it could also be one char shorter:
f .'a
and probably that is what you wanted to say

i prefer the /: version as it is a bit more explicit
f .'a - could also mean that f is a list of functions
(f;f;f;f;f). 'a

Regards,
Attila
On 20 Mar 2012, at 10:33, Felix Lungu wrote:

> then
>
> (f.)‘a
>
> On 19 Mar 2012, at 14:45, Attila Vrabecz wrote:
>
>> nope, the OP originally said
>>> imaging that i have a table as follows:
>>> a
>>> 1 2 3
>>> 4 5 6
>>> 3 4 5
>>> 6 7 8
>>> 2 3 5
>>
>> so he has a list of rows
>> not a list of columns
>>
>> however you are of course right
>> if he were to have “a” the other way around
>> that would be the way to compute it
>> and it is actually good idea for performance reasons
>>
>> Cheers,
>> Attila
>>
>> On 19 Mar 2012, at 09:31, Felix Lungu wrote:
>>
>>> nope. the formatting of the sample is bad. a is not a table but a =
matrix.
>>>
>>> for the first iteration x y z is 1 2 3.
>>> q)a:(1 2 3)+:3*til 5
>>> q)a
>>> 1 4 7 10 13
>>> 2 5 8 11 14
>>> 3 6 9 12 15
>>> q)f:{x,y,z}
>>> q)(f’). a
>>> 1 2 3
>>> 4 5 6
>>> 7 8 9
>>> 10 11 12
>>> 13 14 15
>>>
>>> On 17 Mar 2012, at 21:58, Attila Vrabecz wrote:
>>>
>>>> that would need a flip
>>>> (f’) . flip a
>>>>
>>>> Cheers,
>>>> Attila
>>>> On 17 Mar 2012, at 19:53, Felix LUNGU wrote:
>>>>
>>>>> (f’) . a
>>>>>
>>>>> =CEn data de 17 martie 2012, 17:02, CHEN, Cheng =
a scris:
>>>>>> hi, gurus
>>>>>>
>>>>>> imaging that i have a table as follows:
>>>>>> a
>>>>>> 1 2 3
>>>>>> 4 5 6
>>>>>> 3 4 5
>>>>>> 6 7 8
>>>>>> 2 3 5
>>>>>>
>>>>>> how to apply a function func[x;y;z] to each row of this table, so =
that for
>>>>>> each row, the item in the first column is x, the item in the =
second column
>>>>>> is y and the item in the 3rd column is z ?
>>>>>>
>>>>>> any idea?
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>> –
>>>>>> CHEN, Cheng
>>>>>>
>>>>>> –
>>>>>> You received this message because you are subscribed to the =
Google Groups
>>>>>> “Kdb+ Personal Developers” group.
>>>>>> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
>>>>>> To unsubscribe from this group, send email to
>>>>>> personal-kdbplus+unsubscribe@googlegroups.com.
>>>>>> For more options, visit this group at
>>>>>> http://groups.google.com/group/personal-kdbplus?hl=en.
>>>>>
>>>>> –
>>>>> You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
>>>>> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
>>>>> To unsubscribe from this group, send email to =
personal-kdbplus+unsubscribe@googlegroups.com.
>>>>> For more options, visit this group at =
http://groups.google.com/group/personal-kdbplus?hl=en.
>>>>>
>>>>
>>>> –
>>>> You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
>>>> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
>>>> To unsubscribe from this group, send email to =
personal-kdbplus+unsubscribe@googlegroups.com.
>>>> For more options, visit this group at =
http://groups.google.com/group/personal-kdbplus?hl=en.
>>>>
>>>
>>> –
>>> You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
>>> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
>>> To unsubscribe from this group, send email to =
personal-kdbplus+unsubscribe@googlegroups.com.
>>> For more options, visit this group at =
http://groups.google.com/group/personal-kdbplus?hl=en.
>>>
>>
>> –
>> You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
>> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
>> To unsubscribe from this group, send email to =
personal-kdbplus+unsubscribe@googlegroups.com.
>> For more options, visit this group at =
http://groups.google.com/group/personal-kdbplus?hl=en.
>>
>
> –
> You received this message because you are subscribed to the Google =
Groups “Kdb+ Personal Developers” group.
> To post to this group, send email to =
personal-kdbplus@googlegroups.com.
> To unsubscribe from this group, send email to =
personal-kdbplus+unsubscribe@googlegroups.com.
> For more options, visit this group at =
http://groups.google.com/group/personal-kdbplus?hl=en.
>


To: personal-kdbplus@googlegroups.com
X-Mailer: Apple Mail (2.1257)

yeah, yeah :)

a pint on me next time i’m in london.

Am 20.03.2012 14:06, schrieb Attila Vrabecz:
> nope, close, but not quite
>
> 1. space is needed between f and .
> or one can use .[f]
> 2. monad’a is k, in q one has to say
> m’[a] or (m’) or m each a
> 3. even if we use corrent syntax in (1.)
> it is not ideal as both these create a projection
> which is obviously slower than direct application
>
> q)\t do[10000;(f .)each a]
> 150
>
> q)\t do[10000;f ./:a]
> 120
>
> So if you want me to elaborate on why I chose to suggest
> f ./:a
>
> because it is
> short, fast and simplest (no parentheses)
>
> in all fairness
> it could also be one char shorter:
> f .'a
> and probably that is what you wanted to say
>
> i prefer the /: version as it is a bit more explicit
> f .'a - could also mean that f is a list of functions
> (f;f;f;f;f). 'a

Cool explanation.
>
> Regards,
> Attila
> On 20 Mar 2012, at 10:33, Felix Lungu wrote:
>
>> then
>>
>> (f.)‘a
>>
>> On 19 Mar 2012, at 14:45, Attila Vrabecz wrote:
>>
>>> nope, the OP originally said
>>>> imaging that i have a table as follows:
>>>> a
>>>> 1 2 3
>>>> 4 5 6
>>>> 3 4 5
>>>> 6 7 8
>>>> 2 3 5
>>> so he has a list of rows
>>> not a list of columns
>>>
>>> however you are of course right
>>> if he were to have “a” the other way around
>>> that would be the way to compute it
>>> and it is actually good idea for performance reasons
>>>
>>> Cheers,
>>> Attila
>>>
>>> On 19 Mar 2012, at 09:31, Felix Lungu wrote:
>>>
>>>> nope. the formatting of the sample is bad. a is not a table but a matrix.
>>>>
>>>> for the first iteration x y z is 1 2 3.
>>>> q)a:(1 2 3)+:3*til 5
>>>> q)a
>>>> 1 4 7 10 13
>>>> 2 5 8 11 14
>>>> 3 6 9 12 15
>>>> q)f:{x,y,z}
>>>> q)(f’). a
>>>> 1 2 3
>>>> 4 5 6
>>>> 7 8 9
>>>> 10 11 12
>>>> 13 14 15
>>>>
>>>> On 17 Mar 2012, at 21:58, Attila Vrabecz wrote:
>>>>
>>>>> that would need a flip
>>>>> (f’) . flip a
>>>>>
>>>>> Cheers,
>>>>> Attila
>>>>> On 17 Mar 2012, at 19:53, Felix LUNGU wrote:
>>>>>
>>>>>> (f’) . a
>>>>>>
>>>>>> ?n data de 17 martie 2012, 17:02, CHEN, Cheng a scris:
>>>>>>> hi, gurus
>>>>>>>
>>>>>>> imaging that i have a table as follows:
>>>>>>> a
>>>>>>> 1 2 3
>>>>>>> 4 5 6
>>>>>>> 3 4 5
>>>>>>> 6 7 8
>>>>>>> 2 3 5
>>>>>>>
>>>>>>> how to apply a function func[x;y;z] to each row of this table, so that for
>>>>>>> each row, the item in the first column is x, the item in the second column
>>>>>>> is y and the item in the 3rd column is z ?
>>>>>>>
>>>>>>> any idea?
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> –
>>>>>>> CHEN, Cheng
>>>>>>>
>>>>>>> –
>>>>>>>

Submitted via Google Groups