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

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

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() / 3)]

[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-2.html
匿名

发表评论

匿名网友

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

确定