NumPy: Create an inner product of two arrays
NumPy Mathematics: Exercise-13 with Solution
Write a NumPy program to create an inner product of two arrays.
import numpy as np x = np.arange(24).reshape((2,3,4)) print("Array x:") print(x) print("Array y:") y = np.arange(4) print(y) print("Inner of x and y arrays:") print(np.inner(x, y))
Array x: [[[ 0 1 2 3] [ 4 5 6 7] [ 8 9 10 11]] [[12 13 14 15] [16 17 18 19] [20 21 22 23]]] Array y: [0 1 2 3] Inner of x and y arrays: [[ 14 38 62] [ 86 110 134]]
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a NumPy program to multiply a matrix by another matrix of complex numbers and create a new matrix of complex numbers.
Next: Write a NumPy program to generate inner, outer, and cross products of matrices and vectors.
What is the difficulty level of this exercise?
Test your Python skills with w3resource's quiz
Python: Tips of the Day
Getting rid of unwanted characters:
You can get rid of whitespaces or any specific character using strip methods in Python. You can use either plain strip for both sides, lstrip for the left side and rstrip for the right side only.
str="+++Welcome python+++" str.strip() print(str)
- New Content published on w3resource:
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework