multiply a vector by a matrix line by line
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !
5 posts
• Page 1 of 1
multiply a vector by a matrix line by line
I am trying to multiply the vector x by the matrix y line by line:
x
100 200 150 25 35
y
1 1 0 0 0
0 0 1 0 1
0 0 0 1 0
to get:
100 200 0 0 0
0 0 150 0 35
0 0 0 25 0
with x and y having any number of columns and y having any number of rows
I tried many thigs but cannot get how to do this...
Please help,
x
100 200 150 25 35
y
1 1 0 0 0
0 0 1 0 1
0 0 0 1 0
to get:
100 200 0 0 0
0 0 150 0 35
0 0 0 25 0
with x and y having any number of columns and y having any number of rows
I tried many thigs but cannot get how to do this...
Please help,
- BenoitM
- Posts: 10
- Joined: Tue Jan 12, 2021 3:04 pm
Re: multiply a vector by a matrix line by line
Your target result implies that you actually want the length of the vector and width of the matrix to conform which seems to be contradicted by the final sentence. However
corrected immediately PL
x ×⍤1⊢ ywill give the answer.
corrected immediately PL
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: multiply a vector by a matrix line by line
The rank operator applies its left function operand to cells of its arguments defined by the ranks in its right vector operand. so in this case 1-cells (rows) in each argument are paired. As there is only one 1-cell in x it is repeated for each in y
-
Phil Last - Posts: 628
- Joined: Thu Jun 18, 2009 6:29 pm
- Location: Wessex
Re: multiply a vector by a matrix line by line
..or just using another way:
-Veli-Matti
x×[2]y
-Veli-Matti
- Veli-Matti
- Posts: 94
- Joined: Sat Nov 28, 2009 3:12 pm
Re: multiply a vector by a matrix line by line
Thank you both!
- BenoitM
- Posts: 10
- Joined: Tue Jan 12, 2021 3:04 pm
5 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group