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.

Sample Solution:-

Python Code:

import numpy as np
x = np.arange(24).reshape((2,3,4))
print("Array x:")
print("Array y:")
y = np.arange(4)
print("Inner of x and y arrays:")
print(np.inner(x, y))

Sample Output:

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]]

Pictorial Presentation:

NumPy Mathematics: Create an inner product of two arrays.

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+++"



+++Welcome python+++