kdb/q:如何将列表重塑为nRows,其中nRows是变量 [英] kdb/q: how to reshape a list into nRows, where nRows is a variable
本文介绍了kdb/q:如何将列表重塑为nRows,其中nRows是变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果要将列表分为两行,可以使用:
If I am to split a list into 2 rows, I can use:
q)2 0N#til 10
但是,以下语法不起作用:
However, the following syntax does not work:
q)n:2
q)n 0N#til 10
如何实现这种重塑?
推荐答案
以下是将列表拆分成矩阵形式的一般语法:
Here is the general syntax to split a list in matrix form:
(list1)#(list2)
如您所见,#"的左侧和右侧是列表.所以这是一个例子:
As you can see, left part and right part of '#' is list. So here is one example:
q)list1: (4;3) / or simply (4 3)
q)list2: til 12
q)list1#list2
我们可以用两种方式制作一个整数列表:
We can make an integer list in 2 way:
- 使用分号作为list1:(2; 3; 4)
- 将空格用作list1:(2 3 4)
但是当您有变量时,选项2不起作用;
But when you have variable, option 2 doesn't work;
q)list1: (n 3) / where n:2
q) `type error
因此,对于您的问题,解决方案是使用分号创建列表:
So for your question, solution is to use semicolon to create list:
q) list1:(n;0N)
q) list1#til 10
这篇关于kdb/q:如何将列表重塑为nRows,其中nRows是变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文