afancy
1
q)x:3#til 10 // For example, i generate list x
q)x
0 1 2
q)type x
7h
// Now I want to convert the list x to 1 x N matrix.
q)size:count x // I first get the size of the list
q)matrix:1 size#x // Then, convert to matrix, but get the error 'type.
'type
You can enlist the vector to form a matrix.<o:p></o:p>
<o:p> </o:p>
q) matrix:enlist til 10<o:p></o:p>
q) matrix[0;0]<o:p></o:p>
q) matrix . 0 0<o:p></o:p>
<o:p> </o:p>
For matrix multiplication you can use mmu or $.<o:p></o:p>
<o:p> </o:p>
Kim<o:p></o:p>
<o:p> </o:p>
Von: personal-kdbplus@googlegroups.com [mailto:personal-kdbplus@googlegroups.com] Im Auftrag von afancy
Gesendet: Mittwoch, 22. Januar 2014 21:47
An: personal-kdbplus@googlegroups.com
Betreff: [personal kdb+] How to convert a list to 1 x n matrix?<o:p></o:p>
<o:p> </o:p>
q)x:3#til 10 // For example, i generate list x<o:p></o:p>
q)x<o:p></o:p>
0 1 2<o:p></o:p>
q)type x <o:p></o:p>
7h<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
// Now I want to convert the list x to 1 x N matrix.<o:p></o:p>
q)size:count x // I first get the size of the list<o:p></o:p>
q)matrix:1 size#x // Then, convert to matrix, but get the error 'type.<o:p></o:p>
'type<o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
<o:p> </o:p>
–
Submitted via Google Groups
wp1
3
You need to concatenated size, as in:
q)(1,size)#x
remember q is evaluating from right to left.
'type happens because result of size#x is being applied onto 1 (which is not a list, so can’t index into an atom).
How about using null to avoid the count part?
q)x:3#til 10 // For example, i generate list x
q)x
0 1 2
q)type x
7h
q)matrix:1 0N#x
q)matrix
0 1 2
q)type matrix
0h