在DolphinDB中如何从向量中提取指定步长的值?

huangapple go评论71阅读模式
英文:

How to extract values from a vector with a specified step in DolphinDB?

问题

我有两个问题:

DolphinDB是否提供任何函数或方法来生成自然数或日期的等差数列?

我还想从一个向量中提取具有指定步长的值。以下是在Python中实现这一目标的示例代码:

x = [1,2,3,4,5,6,7]
print(x[::3])
//输出:[1, 4, 7]

在DolphinDB中如何实现这个功能?

英文:

I have two quetions:

Does DolphinDB offer any functions or methods to generate an
arithmetic sequence of natural numbers or dates?

I also want to extract values from a vector with a specified step. Below is an example of how this is done in Python:

x = [1,2,3,4,5,6,7]
print(x[::3])
//output: [1, 4, 7]

How can I achieve this in DolphinDB?

答案1

得分: 1

对于你的第一个问题,可以尝试以下方法:

2020.01.01 + 12*0..10

对于你的第二个问题,你可以先根据所需的步长计算出索引,然后再提取值:

a = 1..10
a[3*til ceil(a.count())]

[1,4,7,10]
英文:

For your first question, try the following method:

2020.01.01 + 12*0..10

For your second question, you can first calculate the indices based on the desired step before extracting the values:

a = 1..10
a[3*til ceil(a.count())]

[1,4,7,10]

huangapple
  • 本文由 发表于 2023年8月9日 14:15:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76865032.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定