NumPy: Multiply the values ​​of two given vectors

NumPy: Basic Exercise-24 with Solution

Write a NumPy program to multiply the values ​​of two given vectors.

Sample Solution :

Python Code :

import numpy as np
x = np.array([1, 8, 3, 5])
y= np.random.randint(0, 11, 4)
result = x * y
print("Multiply the values of two said vectors:")

Sample Output:

[1 8 3 5]
[1 6 4 6]
Multiply the values of two said vectors:
[ 1 48 12 30]                         

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to create a vector of length 5 filled with arbitrary integers from 0 to 10.
Next: Write a NumPy program to create a 3x4 matrix filled with values ​​from 10 to 21.

What is the difficulty level of this exercise?

Test your Python skills with w3resource's quiz

Python: Tips of the Day

Returns the symmetric difference between two lists, after applying the provided function to each list element of both


def tips_symmetric_difference_by(p, q, fn):
  _p, _q = set(map(fn, p)), set(map(fn, q))
  return [item for item in p if fn(item) not in _q] + [item for item in q if fn(item) not in _p]
from math import floor
print(tips_symmetric_difference_by([4.2, 2.4], [4.6, 6.8],floor))


[2.4, 6.8]