当使用每个时,q 如何组合字典输出以创建 table?

how does q combine dictionary outputs to create table when each is used?

time_snap_temp:((1 2 3 4);(4 5 6 7);(7 8 9 10))
col_names:`AA`AB`AC`AD
f_try: {y!x}[;col_names]
agg:f_try each time_snap_temp
one_dict: f_try time_snap_temp[0]  

one_dict 是预期的字典,但 agg 是 table。 q如何结合字典在agg中创建一个table?

感谢并感谢您的帮助。

A table 实际上是一个字典列表,当对每个字典使用 f_try 时,它将输出一个字典列表,这些字典被提升为 table。当仅将 f_trytime_snap_temp 中的第一个条目一起使用时,仅输出一个字典,因此仍然是一个字典。

// see how using 1# and each here will output list of dictionaries of length 1 and also get promoted to a table
q)f_try each 1#time_snap_temp
AA AB AC AD
-----------
1  2  3  4

A table 是 like 词典的列表;也就是说,具有相同键的字典。 (关键顺序很重要。)

f_try 可以是 Dict !:

的简单投影
q)f_try:`AA`AB`AC`AD!
q)f_try each time_snap_temp
AA AB AC AD
-----------
1  2  3  4
4  5  6  7
7  8  9  10

或者直接使用字典 Each Right /:

q)`AA`AB`AC`AD!/:time_snap_temp / key is constant
AA AB AC AD
-----------
1  2  3  4
4  5  6  7
7  8  9  10

但是如果键不匹配

q)4 4 4?\:col_names  / mix up the keys: Deal Each Left
AC AC AD AC
AA AB AB AC
AD AD AC AB
q)(4 4 4?\:col_names)!'time_snap_temp
`AC`AD`AD`AA!1 2 3 4
`AC`AB`AA`AB!4 5 6 7
`AA`AD`AD`AD!7 8 9 10

如果键不相同,则列表只是字典列表。它们必须是 like 字典才能产生 table.

使用矩阵,您不需要像这样遍历行。您可以翻转它,使用 Dict 制作列字典(same-length 列的字典)并翻转回 table。 (flip 关键字只是设置一个内部标志,所以它是一个廉价的操作。)

q)flip `AA`AB`AC`AD!flip time_snap_temp
AA AB AC AD
-----------
1  2  3  4
4  5  6  7
7  8  9  10