英文:
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]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论