cancel
Showing results for
Did you mean:

## Matrix indexing - operations on all rows except first New Contributor
Say I have a square matrix of numbers assigned to A.

How would I index A so all rows except A 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 = A*v;
X = A*v;.
...
X[n] = A*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 New Contributor

> How would I index A so all rows except A 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*/:v
0 10 20 30
0 20 40 60
0 30 60 90
0 40 80 120

HTH,
Pawel

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

How would I index A so all rows except A 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 = A*v;
X = A*v;.
...
X[n] = A*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.  