# How to convert a list to 1 x n matrix?

**URL:** https://forum.kx.com/t/how-to-convert-a-list-to-1-x-n-matrix/8590
**Category:** Community Support
**Tags:** kdb-and-q
**Created:** [January 22, 2014, 8:46pm UTC](https://forum.kx.com/t/how-to-convert-a-list-to-1-x-n-matrix/8590 "2014-01-22T20:46:00Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![afancy](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@afancy](https://forum.kx.com/u/afancy)
#### Post date: [January 22, 2014, 8:46pm UTC](https://forum.kx.com/t/how-to-convert-a-list-to-1-x-n-matrix/8590/1 "2014-01-22T20:46:00Z")

</div>

q)x:3#til 10 // For example, i generate list x

q)x

0 1 2

q)type x &nbsp;

7h

// Now I want to convert the list x to 1 x N matrix.

q)size:count x &nbsp;// I first get the size of the list

q)matrix:1 size#x &nbsp;// Then, convert to matrix, but get the error 'type.

'type

---

<div class="post-metadata">

### Author: ![kuentang](https://avatars.discourse-cdn.com/v4/letter/k/bc8723/32.png) [@kuentang](https://forum.kx.com/u/kuentang)
#### Post date: [January 22, 2014, 9:04pm UTC](https://forum.kx.com/t/how-to-convert-a-list-to-1-x-n-matrix/8590/2 "2014-01-22T21:04:00Z")

</div>

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) [[mailto: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](mailto: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 &nbsp;\<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 &nbsp;// I first get the size of the list\<o:p\>\</o:p\>

q)matrix:1 size#x &nbsp;// 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

---

<div class="post-metadata">

### Author: ![wp1](https://avatars.discourse-cdn.com/v4/letter/w/db5fbb/32.png) [@wp1](https://forum.kx.com/u/wp1)
#### Post date: [January 22, 2014, 9:04pm UTC](https://forum.kx.com/t/how-to-convert-a-list-to-1-x-n-matrix/8590/3 "2014-01-22T21:04:00Z")

</div>

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).

---

<div class="post-metadata">

### Author: ![WooiKent\_Lee](https://avatars.discourse-cdn.com/v4/letter/w/5f8ce5/32.png) [@WooiKent\_Lee](https://forum.kx.com/u/WooiKent_Lee)
#### Post date: [January 23, 2014, 11:33am UTC](https://forum.kx.com/t/how-to-convert-a-list-to-1-x-n-matrix/8590/4 "2014-01-23T11:33:00Z")

</div>

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 &nbsp;

7h

q)matrix:1 0N#x

q)matrix

0 1 2

q)type matrix

0h
