lan1
August 26, 2021, 4:13am
1
Hi, everyone.
I have some questions about wavg function.
0 wavg 5 / 5 5 wavg 5 / 5 2 wavg 2 3 7 / 4 5 2 3 wavg 3 / 3
According to the doc, the x and y of wavg[x;y] must both be numeric lists. But for these invalid inputs, wavg still yields some results. Could anyone help me understand the results of these invalid x and y?
What’s the behavior of wavg when x and y aren’t numeric lists or they don’t conform? It seems like avg y but I’m not sure.
If you know more about wavg’s implementation detail, please help me. Thanks.
lkerr1
August 27, 2021, 3:42pm
2
Hi Ian,
Great question! We’re working on an answer for you.
Thanks for your contribution and getting us thinking!
Laura
lan1
August 31, 2021, 2:28am
3
Thanks for your reply and looking forward to the answer!
LeahS1
September 2, 2021, 2:36pm
4
Hello Ian,
Thank you for bringing this great question to our attention.
We can confirm that
0 wavg x
should indeed be 0n. This is a bug and will be fixed by our team. Thank you for sharing this observation.
The following is an explanation for the other cases:
Atoms on both sides behave as if enlisted to single item vectors.
5 wavg 5 / 5 enlist[5] wavg enlist[5] /5
An atom on one side and a vector on the other behaves as if the atom is repeated to match the length of the vector.
2 wavg 2 3 7 / 4 2 2 2 wavg 2 3 7 /4 5 2 3 wavg 3 / 3 5 2 3 wavg 3 3 3 /3
We hope our feedback is helpful for you.
Thank you again for your contribution and engagement with our KX community. We look forward to more.
Kind regards,
Leah
lan1
September 6, 2021, 4:30am
5
Hi Leah,
Thanks for your explanation.
So for the case “0 wavg x”, it is equivalent to (0*x)%0 => 0%0=0n. It really makes sense.
Thank you and your team again.
Todays release kdb+4.0 2021.10.01 contains a fix for the issue in your first example:
q)0 wavg 5
0n