kdb 列表中的索引 i 返回的值是多少
What is the value returned from index i from a list in kdb
我能理解 i 表示列表中项目的索引,但是当我使用 i 表示法获取值时,在不同情况下会得到不同的结果:
/Sorted list with unique elements
q)a: 0 1 2 3 4 5 6 7 / sorted list with 8 unique elements
q)a[i]
,3 / why are we getting 3 here?
q)a: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 / sorted list of 18 unique elements
q)a[i]
,3
/ sorted list with non-distinct elements
q)a: 0 1 2 2 3 4 6 8 9
q)a[i]
,2
q)a: 0 1 2 2 3 3 4 6 8 9
q)a[i]
,2
/Unsorted unique elements
q)show a:-10?10
6 1 7 3 4 8 5 0 2 9
q)a[i]
,3
/Unsorted non-distinct elements
q)show a:10?10
9 5 2 3 9 5 9 7 6 6
q)a[i]
,3
/ list with nulls
q)a:1 3 5 2 0N 5 0N 6
q)a[i]
,2
q)a:1 5 0N 5 0N 6
q)a[i]
,5
于是问题来了,a[i] return每次做什么?
它是 return 列表中的随机值还是有任何 logic/rule 我们在上述情况下通过它获得输出?
在您的情况下,您似乎在初次调用 a[i]
之前在您的 q 会话中设置了 i = 3
?
在上面引用的每种情况下,给定索引从 0 开始返回数组的第 4 个元素。
// ascending list of integers
q)show a:til 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// i not defined in the session
q)a[i]
'i
[0] i
// set i to be 3
q)i:3
// try again
q)a[i]
3
// set a as an unsorted list of floats
q)show a:10?1f
0.3927524 0.5170911 0.5159796 0.4066642 0.1780839 0.3017723 0.785033 0.534709..
// return the ith element
q)a[i]
0.4066642
我能理解 i 表示列表中项目的索引,但是当我使用 i 表示法获取值时,在不同情况下会得到不同的结果:
/Sorted list with unique elements
q)a: 0 1 2 3 4 5 6 7 / sorted list with 8 unique elements
q)a[i]
,3 / why are we getting 3 here?
q)a: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 / sorted list of 18 unique elements
q)a[i]
,3
/ sorted list with non-distinct elements
q)a: 0 1 2 2 3 4 6 8 9
q)a[i]
,2
q)a: 0 1 2 2 3 3 4 6 8 9
q)a[i]
,2
/Unsorted unique elements
q)show a:-10?10
6 1 7 3 4 8 5 0 2 9
q)a[i]
,3
/Unsorted non-distinct elements
q)show a:10?10
9 5 2 3 9 5 9 7 6 6
q)a[i]
,3
/ list with nulls
q)a:1 3 5 2 0N 5 0N 6
q)a[i]
,2
q)a:1 5 0N 5 0N 6
q)a[i]
,5
于是问题来了,a[i] return每次做什么?
它是 return 列表中的随机值还是有任何 logic/rule 我们在上述情况下通过它获得输出?
在您的情况下,您似乎在初次调用 a[i]
之前在您的 q 会话中设置了 i = 3
?
在上面引用的每种情况下,给定索引从 0 开始返回数组的第 4 个元素。
// ascending list of integers
q)show a:til 20
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
// i not defined in the session
q)a[i]
'i
[0] i
// set i to be 3
q)i:3
// try again
q)a[i]
3
// set a as an unsorted list of floats
q)show a:10?1f
0.3927524 0.5170911 0.5159796 0.4066642 0.1780839 0.3017723 0.785033 0.534709..
// return the ith element
q)a[i]
0.4066642