Take a column of a matrix and make it a row in kdb

kdb where
kdb+/q
kdb+ data types
q for mortals
kdb+ select column as
kdb functional select
kdb+ row index
kdb+ matrix

Consider the matrix:

1 2 3
4 5 6
7 8 9 

I'd like to take the middle column, assign it to a variable, and replace the middle row with it, giving me

1 2 3
2 5 8
7 8 9 

I'm extracting the middle column using

a:m[;enlist1]

which returns

2
5
8

How do I replace the middle row with a? Is a flip necessary?

Thanks.

kdb - Adding a row to a matrix in Q?, A matrix in q is just a list of lists where inner lists represent rows. m: ((1 2 3);(4 5 6​);(7 8 9)). In order to add one more row all you have to do is add one more inner  To take an entire row, use one index to specify the row: To take an entire column, you need to select all rows with All and specify the column: To pick out a submatrix, you can use Span ( ;; ).

If you want to update the matrix in place you can use

q)show m:(3;3)#1+til 10
1 2 3
4 5 6
7 8 9
q)a:m[;1]
q)m[1]:a
q)show m
1 2 3
2 5 8
7 8 9
q)

cutting out "a" all you need is:

m[1]:m[;1]

Take – Reference – kdb+ and q documentation, Take is a q operator that selects leading or trailing items from a list or dictionary, named entries from a dictionary, or named columns from a table. Where x is a vector, returns a matrix or higher-dimensional array; count x gives the number of From V3.4, x can have length greater than 2 – but may not contain nulls. extract first row from matrix. Learn more about matrix . Skip to content. for column C of matrix M. Basic MATLAB indexing is explained in the introductory tutorials:

Making it slightly more generic where you can define the operation, row, and column

q)m:3 cut 1+til 9
1 2 3
4 5 6
7 8 9

Assigning the middle column to middle row :

q){[ m;o;i1;i2] .[m;enlist i1;o; flip[m] i2 ] }[m;:;1;1]
1 2 3
2 5 8
7 8 9

Adding the middle column to middle row by passing o as +

q){[ m;o;i1;i2] .[m;enlist i1;o; flip[m] i2 ] }[m;+;1;1]
1 2  3
6 10 14
7 8  9

Shape - Q Phrasebook - Kdb+ and q documentation, It corresponds to the dimensions of a rectangular array, thus the array's rank: the Conform table x columns to list y Array with shape of y and x as its rows. How to Convert a Row to a Column in Excel the Easy Way Lori Kaufman @howtogeek Updated September 28, 2017, 5:33pm EDT You’ve set up a worksheet, when you realize it would look better if the rows and columns were reversed.

select, Select – Reference – kdb+ and q documentation, Select only the columns you will use. Use the most restrictive constraint first. Ensure you have a suitable attribute on the first non-virtual constraint (e.g. `p or  While MATLAB displays arrays according to their defined sizes and shapes, they are actually stored in memory as a single column of elements. A good way to visualize this concept is with a matrix. While the following array is displayed as a 3-by-3 matrix, MATLAB stores it as a single column made up of the columns of A appended one after the other.

3. Lists - Q for Mortals, They have a simplified notation, take less storage and compute faster than It is possible to create a (possibly ragged) array of a given number of rows or  Transpose reorients the content of copied cells when pasting. Data in rows is pasted into columns and vice versa. Here's how you can transpose cell content: Copy the cell range. Select the empty cells where you want to paste the transposed data. On the Home tab, click the Paste icon, and select Paste Transpose.

Tables | Q For Mortals, All tables have type 98h . q)type t 98h. Copy. The proper way to extract a table column is by eliding the row index. For table columns (only), you can omit the  Extracting data from a matrix in Scilab So far we have learned how to define a matrix in Scilab. In this article we’ll learn how to extract a particular value from a matrix or a particular set of values (e.g. one column, one row, a sub-matrix).

Comments
  • Marvellous, thank you. I'm not too familiar with dot amend. I'll do a bit of research. Thanks very much!