multiply a vector by a matrix line by line

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
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 !

multiply a vector by a matrix line by line

Postby BenoitM on Mon Jan 15, 2024 8:45 am

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,
BenoitM
 
Posts: 10
Joined: Tue Jan 12, 2021 3:04 pm

Re: multiply a vector by a matrix line by line

Postby Phil Last on Mon Jan 15, 2024 9:12 am

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
      x ×⍤1⊢ y
will give the answer.

corrected immediately PL
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: multiply a vector by a matrix line by line

Postby Phil Last on Mon Jan 15, 2024 9:19 am

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
User avatar
Phil Last
 
Posts: 628
Joined: Thu Jun 18, 2009 6:29 pm
Location: Wessex

Re: multiply a vector by a matrix line by line

Postby Veli-Matti on Mon Jan 15, 2024 2:03 pm

..or just using another way:
      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

Postby BenoitM on Tue Jan 16, 2024 6:13 am

Thank you both!
BenoitM
 
Posts: 10
Joined: Tue Jan 12, 2021 3:04 pm


Return to APL Chat

Who is online

Users browsing this forum: No registered users and 1 guest