cancel
Showing results for 
Search instead for 
Did you mean: 

Matrix indexing - operations on all rows except first

adnan_gazi01
New Contributor
Say I have a square matrix of numbers assigned to A.

How would I index A so all rows except A[0] could have an operation applied to it?

Also, say I have an list, v, the length of A's vectors, how would I create a new matrix, X, which contains the first row of A multipled by each constant in the list?

i.e.
X[0] = A[0]*v[0];
X[1] = A[0]*v[1];.
...
X[n] = A[0]*v[n];


I want to do this without a loop, working with an arbitrarily-sized n.

Any help would be appreciated.

Thanks.

2 REPLIES 2

pawel_tryfon
New Contributor
Adnan,
Please find the answers inline.

> How would I index A so all rows except A[0] could have an operation applied to it?

q)A:4 4#til  16
q)A
0  1  2  3
4  5  6  7
8  9  10 11
12 13 14 15
q)A[1_til count A]
4  5  6  7
8  9  10 11
12 13 14 15

An example of functional amend:

q)@[A;1_til count A;neg]
0   1   2   3 
-4  -5  -6  -7
-8  -9  -10 -11
-12 -13 -14 -15


> Also, say I have an list, v, the length of A's vectors, how would I create a new matrix, X, which contains the first row of A multiplied by each constant in the list?
You can use each-right adverb (http://code.kx.com/wiki/Reference/SlashColon). An example below:

q)v:10 20 30 40
q)v
10 20 30 40
q)A[0]*/:v
0 10 20 30
0 20 40 60
0 30 60 90
0 40 80 120

HTH,
Pawel



2013/10/27 Adnan G <adnan.gazi01@gmail.com>
Say I have a square matrix of numbers assigned to A.

How would I index A so all rows except A[0] could have an operation applied to it?

Also, say I have an list, v, the length of A's vectors, how would I create a new matrix, X, which contains the first row of A multipled by each constant in the list?

i.e.
X[0] = A[0]*v[0];
X[1] = A[0]*v[1];.
...
X[n] = A[0]*v[n];


I want to do this without a loop, working with an arbitrarily-sized n.

Any help would be appreciated.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Kdb+ Personal Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to personal-kdbplus+unsubscribe@googlegroups.com.
To post to this group, send email to personal-kdbplus@googlegroups.com.
Visit this group at http://groups.google.com/group/personal-kdbplus.
For more options, visit https://groups.google.com/groups/opt_out.

Ahhh thanks a lot!

That really helped me out.