如何用功能性的,基于数组的语言(如K(或Q))表达这种命令性功能?
在草率的C ++中:
vector<int> x(10), y(10); // Assume these are initialized with some values.
// BTW, 4 is just a const -- it's part of the algorithm and is arbitrarily chosen.
vector<int> result1(x.size() - 4 + 1); // A place to hold a resulting array.
vector<int> result2(x.size() - 4 + 1); // A place to hold another resulting array.
// Here's the code I want to express functionally.
for (int i = 0; i <= x.size() …Run Code Online (Sandbox Code Playgroud) 的.最简单形式的运算符用于索引列表.您如何在此代码中解释其在英语中的用法?
if[x~"last";upd:{[t;x].[t;();,;r::select by sym from x]}]
Run Code Online (Sandbox Code Playgroud)
我也不理解这一行中的空列表和::运算符,但也许它们一旦有意义就会有意义.被清除了.
我是KDB的新手(对不起,如果这个问题很愚蠢).我正在创建下表
q)dsPricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$())
q)dsPricing:([id:`int$(); date:`date$()] open:`float$();close:`float$();high:`float$();low:`float$();volume:`int$())
q)`dsPricing insert(123;2003.03.23;1.0;3.0;4.0;2.0;1000)
q)`dsPricing insert(123;2003.03.24;1.0;3.0;4.0;2.0;2000)
q)save `:dsPricing
Run Code Online (Sandbox Code Playgroud)
让我们说保存后退出.启动q之后,我想在那里添加另一个定价项而不加载整个文件,因为文件可能很大
q)`dsPricing insert(123;2003.03.25;1.0;3.0;4.0;2.0;1500)
Run Code Online (Sandbox Code Playgroud)
我一直在看.Q.dpft,但我无法弄明白.此表/文件也不需要分区.
谢谢
如何使用功能方式更新q词典中的值?
例:
x: `1`2`3;
d: x!x;
show[d];
// d ->
// 1 | 1
// 2 | 2
// 3 | 3
// TODO change d:
show[d];
// d ->
// 1 | 11
// 2 | 22
// 3 | 3
Run Code Online (Sandbox Code Playgroud) 简单的问题 - 我已经使用Python 3.6成功连接到Coinbase API并在我的控制台中接收BTC买/卖价格.
我想将它连接到一个kdb数据库并开始创建一个滴答数据的HDB,但我对如何构建这个设置有点困惑,即将get请求推送到数据库进行存储.我的python代码看起来像......
api_key = 'XXXXX'
api_secret = 'XXXXX'
from coinbase.wallet.client import Client
import time, requests
client = Client(api_key, api_secret)
starttime = time.time()
while True:
buy_price = client.get_buy_price(currency_pair = 'BTC-USD')
sell_price = client.get_sell_price(currency_pair = 'BTC-USD')
time.sleep(10.0)
print(buy_price)
print(sell_price)
print("=-=-=-=-=-=")
Run Code Online (Sandbox Code Playgroud)
控制台打印Feed,看起来像......
{
"amount": "8034.79",
"base": "BTC",
"currency": "USD"
}
{
"amount": "7875.67",
"base": "BTC",
"currency": "USD"
}
=-=-=-=-=-=
{
"amount": "8034.80",
"base": "BTC",
"currency": "USD"
}
{
"amount": "7875.97",
"base": "BTC",
"currency": "USD"
}
=-=-=-=-=-=
Run Code Online (Sandbox Code Playgroud)
在本地存储这些数据的任何指导都会有所帮助.如果您需要任何其他信息,请与我们联系.
先感谢您!
假设我有一张桌子
tbl:flip `id`evt!(1 1 1 2 2 2 2 2 3 3; `a`b`c`a`b`b`b`c`a`c)
Run Code Online (Sandbox Code Playgroud)
如何有效地计算evt的出现次数,但每个id只能计算一次
因此,结果应该如下(或将evt映射到唯一计数的任何其他格式)
res:flip `evt`ct !(`a`b`c; 3 2 3)
Run Code Online (Sandbox Code Playgroud) 我有以下查询用于从分区表中删除行,但它不起作用.用于删除分区表中的行的方法是什么?
delete from SecurityLoan where lender=`SCOTIA, date in inDays, portfolio in portfoliolist
Run Code Online (Sandbox Code Playgroud)
请注意,inDays并portfoliolist在列表
在KDB中,为什么我可以这样做:
{[x;y]x+y} ./: enlist[(1;1);(2;1)]
Run Code Online (Sandbox Code Playgroud)
但不是这个:
{[x]x+1} ./: enlist[1;2]
Run Code Online (Sandbox Code Playgroud)
如果我使用这个:
{[x]x+1} each enlist[1;2]
Run Code Online (Sandbox Code Playgroud)
然后它工作.为什么采取2个参数会产生影响?
假设我有以下两个列表:
x : `a`b`c`d;
y : `a`b`e`f;
Run Code Online (Sandbox Code Playgroud)
对于交叉路口,有inter运营商:
q)x inter y
`a`b
Run Code Online (Sandbox Code Playgroud)
是否有类似的运算符来做EXCLUSIVE OR这样的事情,我会得到:
q)x outer y
`c`d`e`f
Run Code Online (Sandbox Code Playgroud)
?