Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- KX Community
- :
- Discussion Forums
- :
- kdb+ and q
- :
- Matrix indexing - operations on all rows except fi...

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Matrix indexing - operations on all rows except first

Options

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2013.10.27 11:36 AM

How would I index A so all rows

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2013.10.27 02:45 PM

Adnan,

Please find the answers inline.> How would I index A so all rows

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

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

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>

How would I index A so all rowsexceptA[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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

2013.10.28 03:32 AM

Ahhh thanks a lot!

That really helped me out.

That really helped me out.

Related Content

Main Office Contacts

**EMEA**

Tel: +44 (0)28 3025 2242

**AMERICAS**

Tel: +1 (212) 447 6700

**APAC**

Tel: +61 (0)2 9236 5700

Useful Information

Popular Links

Follow Us

KX. All Rights Reserved.

KX and kdb+ are registered trademarks of KX Systems, Inc., a subsidiary of FD Technologies plc.