Reputation:
There is a function in kdb generating multiple tables as results. My main aim is to analyze each of the table generated using python.
Is there a way I can make it return a list of table or some dictionary of tables so I can export it to python or should I try something else? Any leads on this is appreciated. Thanks
Upvotes: 0
Views: 2275
Reputation: 909
It's not clear what you're asking - do you have a function which generates multiple tables? And you want to return a list of these tables? If that is the case and you have something like
f:{t:([]a:x?`1;b:x?10);q:([]c:x?`2;d:x?10f)}
that you want to modify to return both t and q, you can just manually construct a list from within the function:
q)f:{t:([]a:x?`1;b:x?10);q:([]c:x?`2;d:x?10f);(t;q)}
q)f 3
+`a`b!(`o`p`l;5 8 5)
+`c`d!(`ig`nf`no;9.149882 9.030751 7.750292)
or alternatively, you can return the tables by using enlist
on each table and joining the results of these operations:
q)f:{t:([]a:x?`1;b:x?10);q:([]c:x?`2;d:x?10f);enlist[t],enlist[q]}
q)f 3
+`a`b!(`n`a`a;6 9 0)
+`c`d!(`nn`mi`om;9.216436 1.809536 6.434637)
Or, if you use each
to pass multiple inputs to a function returning a single table, the results will naturally be a list of tables:
q)f:{t:([]a:x?`1;b:x?10)}
q)f each 3 3
+`a`b!(`l`o`d;9 5 2)
+`a`b!(`h`m`g;9 5 9)
One other modification you could make is to join each table onto a table list as it's created:
q)f:{tl:();
t:([]a:x?`1;b:x?10);
tl,:enlist t;
q:([]c:x?`2;d:x?10f);
tl,:enlist q;
tl}
q)f 3
+`a`b!(`a`l`i;1 9 1)
+`c`d!(`db`mi`la;2.371288 5.67081 4.269177)
This is quite verbose with assigning tables, but you don't need to do so directly, you could also do:
q)f:{tl:();
tl,:enlist ([]a:x?`1;b:x?10);
tl,:enlist ([]c:x?`2;d:x?10f);
tl}
To get the same output, joining each table to the list as it's created, and so returning a list of tables.
Upvotes: 3