take

语法

take(X, n)

参数

X 可以是标量、向量或矩阵。n 是一个整数。

详情

如果 X 是标量,生成n个 X。如果 X 是向量或矩阵,从 X 中循环地依次取值,共取n个值。结果是一个向量。

例子

$ take(10,5);
[10,10,10,10,10]

$ x=`IBM`C`AAPL`BABA;
$ take(x,10);
["IBM","C","AAPL","BABA","IBM","C","AAPL","BABA","IBM","C"]
// sequentially and iteratively take 10 elements from vector x

$ x=3 5 4 6 9;
$ take(x,3);
[3,5,4]


$ x=1..3;
$ x.take(10);
[1,2,3,1,2,3,1,2,3,1]

$ take(1 2 3, 10);
[1,2,3,1,2,3,1,2,3,1]


$ take(1,10);
[1,1,1,1,1,1,1,1,1,1]
// an efficient way to generate a vector with default values.


$ x=take(1,0);
// return an empty INT VECTOR

$ x;
[]

$ typestr x;
FAST INT VECTOR


$ x=1..12$3:4;
$ take(x,2);
[1,2]

$ take(x,-2);
[11,12]