在表上使用迭代器
我有这个表:
A:2.34889 2.484112 1.045939 3.359097 1.642348 1.298948 3.046995 4.077684
B:3.845017 3.762336 3.287893 3.338063 5.861462 5.401914 3.537128 5.27197
t:([] AA:A;BB:B)
-1 + prd select (-1#AA)%(1#AA) from t
-1 + prd select (-1#BB)%(1#BB) from t
我想知道如何将
AA| 0.7360047
BB| 0.3711175
最后两行修改为迭代 AA 和 BB 的单行?例如,如果我有 10 个符号,我只需编写一行即可输出 10 个结果。
另外对问题标题表示歉意,我不确定如何很好地表达它,但如果需要的话很乐意进行编辑。
I have this table:
A:2.34889 2.484112 1.045939 3.359097 1.642348 1.298948 3.046995 4.077684
B:3.845017 3.762336 3.287893 3.338063 5.861462 5.401914 3.537128 5.27197
t:([] AA:A;BB:B)
-1 + prd select (-1#AA)%(1#AA) from t
-1 + prd select (-1#BB)%(1#BB) from t
which outputs
AA| 0.7360047
BB| 0.3711175
I was wondering how I can modify the last two lines into a single line that iterates over AA and BB? For example, if I had 10 symbols, I would only have to write a single line to output the 10 results.
Also apologies on the question title, I am not sure how to phrase it well but am happy to edit if required.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
桌子上的迭代器可以行升起(由0n!下方证明):
或flip列:
对于这种情况,您可以执行后者并将您的函数应用于每个迭代器的所有列:
使用
##或
选择
以获取要应用该功能的列的子集,如果需要:更一般而言,当试图构建类似的代码以应用于列列表功能表单时,可以很有用要注意: https://code.kx.com/q/q/basics/funs/funsql/
Iterators on tables can either be row rise (demonstrated by 0N! below):
Or column wise with flip:
For this case, you could do the latter and apply your function to all columns with the each iterator:
Use
#
orselect
to get the subset of columns you want to apply the function to if needs be:More generally, when trying to build up similar code to apply to a list of columns functional form can be useful to be aware of: https://code.kx.com/q/basics/funsql/
马茨的答案是一个更好、更通用的答案,但在您的特定示例中,逻辑可以很简单:
Matts answer is a better and more general answer but in your particular example the logic can be as simple as:
无需迭代列。
这里的迭代器的最佳用途是每个人都左将同时应用
第一个
和最后
将其应用于t
。该表是2列列表,因此您可以应用鸿沟。
为了重复使用定义此功能,它是三个联合国的组成,此处是为了清晰:
适用于任何数量的列。
No need to iterate through the columns.
The best use of iterators here is Each Left to apply both
first
andlast
tot
.That table is a 2-list, so you can apply Divide.
To define this for re-use, it’s a composition of three unaries, here spaced for clarity:
Works for any number of columns.