Python Forum
row multiplication using vectorization
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
row multiplication using vectorization
#1
Dear All

Coming from matlab, I'm progessively moving to Numpy/Python; I'm looking if the following calculation can be done (I looked tuto and so on with no sucess so far):

(Matlab code)
Quote:a = (1:5)'
b = (6:10)'
c = a .* b

Note the dot "." in front of the "*" that uses vectorization and provides a new vector [6, 14, 24, 36, 50].

Does somebody ever experienced such vectorization?

Thanks for your feedback

Paul
Reply
#2
Moving from matlab environment to numpy/scipy/matplotlib one is pretty simple.
Your example could be rewritten as follows:

import numpy as np
a = np.arange(1, 6)
b = np.arange(6, 11)
c = a * b # element-wise product (in matlab .*)
Or may be I misunderstood something here...
Reply
#3
Thanks for the answer

Humm of course I did it, but I got a number as a result (130 here); restarting Spyder fixed the issue and I'm wondering if the issue does not come from it ...

Is there any keyword to force to "clear" all the variables and other inputs prior to run a code?

Paul
Reply
#4
Could you provide a piece of code you used?

My code snippet leads to the following result:
Output:
>>> c array([ 6, 14, 24, 36, 50])
Reply
#5
I did exactly what you proposed; I failed at the beginning but now it works; I guess the issue did not come from Python or Numpy, but from the Idle itself.

Thanks for your support
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Material for vectorization paul18fr 0 1,619 Sep-17-2019, 10:13 AM
Last Post: paul18fr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020