Calculating the dot product of NumPy arrays
Python Pandas Numpy: Exercise-20 with Solution
Calculate the dot product of two NumPy arrays.
Sample Solution-1:
Python Code:
import numpy as np
# Create two NumPy arrays
array1 = np.array([1, 2, 3])
array2 = np.array([4, 5, 6])
# Calculate the dot product
dot_product = np.dot(array1, array2)
# Display the result
print(dot_product)
Output:
32
Sample Solution-2:
Python Code:
import numpy as np
# Create two NumPy arrays
array1 = np.array([1, 2, 3])
array2 = np.array([4, 5, 6])
# Calculate the dot product
dot_product = array1 @ array2
# Display the result
print(dot_product)
Output:
21
Flowchart:
Python Code Editor:
Previous: Performing element-wise addition in NumPy arrays.
Next: Finding index of maximum and minimum values in a NumPy array.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/python-exercises/pandas_numpy/pandas_numpy-exercise-20.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics