如何将函数计算为 KDB 中的矩阵?
假设我有一个根据 i 和 j 坐标定义矩阵的函数:
f: {y+2*x}
我正在尝试创建一个方阵来评估该函数地点。
我知道它需要类似于 f ' (til 5) /:\: til 5
,但我很难休息。
Let's say I've got a function that defines a matrix in terms of it's i
and j
coordinates:
f: {y+2*x}
I'm trying to create a square matrix that evaluates this function at all locations.
I know it needs to be something like f ' (til 5) /:\: til 5
, but I'm struggling with rest.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
稍微重新提出您的问题,您想创建一个矩阵a = [a ij ],其中a ij = f(i,j),i,j = 0 .. N-1。
换句话说,您需要评估i和j的所有可能组合的
f
。因此:ps no,
(til 5)/:\:til 5
不是恰好您需要的东西,而是关闭。您正在生成所有 pairs 的列表 ie,您正在配对或加入til 5
的第一个元素,即(另一个)til 5
的每个元素一一,然后是第二个等。因此,您需要加入操作员( https:// code.kx.com/q/ref/join/ ):Rephrasing your question a bit, you want to create a matrix A = [aij] where aij = f(i, j), i, j = 0..N-1.
In other words you want to evaluate
f
for all possible combinations of i and j. So:P.S. No,
(til 5) /:\: til 5
is not exactly what you'd need but close. You are generating a list of all pairs i.e. you are pairing or joining the first element oftil 5
with every element of (another)til 5
one by one, then the second , etc. So you need the join operator (https://code.kx.com/q/ref/join/):你很接近。但不需要生成所有坐标对然后迭代它们。 左右各左
/:\:
为您管理所有这些并返回您想要的矩阵。You were close. But there is no need to generate all the coordinate pairs and then iterate over them. Each Right Each Left
/:\:
manages all that for you and returns the matrix you want.