w3resource
NumPy Exercises

NumPy: Compute the inner product of two given vectors

NumPy: Basic Exercise-33 with Solution

Write a NumPy program to compute the inner product of two given vectors.

Sample Solution :

Python Code :

import numpy as np
x = np.array([4, 5])
y = np.array([7, 10])
print("Original vectors:")
print(x)
print(y)
print("Inner product of said vectors:")
print(np.dot(x, y))

Sample Output:

Original vectors:
[4 5]
[ 7 10]
Inner product of said vectors:
78                         

Pictorial Presentation:

NumPy: Compute the inner product of two given vectors.

Python Code Editor:


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

Previous: Write a NumPy program to compute sum of all elements, sum of each column and sum of each row of an given array.
Next: Write a NumPy program to add a vector to each row of a given matrix.

What is the difficulty level of this exercise?