numpy.inner () in python

Arrays | NumPy | Python Methods and Functions

numpy.inner (arr1, arr2) : numpy.inner (arr1, arr2) inner product of two arrays.

  Parameters:   arr1, arr2:  array to be evaluated.  Return:  Inner product of the two arrays. 

Code # 1:

# Python program illustrating
# numpy.inner () method

  

import numpy as geek 

 
# Scalars

product = geek.inner ( 5 , 4

print ( "inner Product of scalar values:" , product) 

 
# 1D array

vector_a = 2 + 3j

vector_b = 4 + 5j

  

product = geek.inner (vector_a, vector_b) 

print ( "inner Product:" , product) 

Exit:

 inner Product of scalar values: 20 inner Product: (-7 + 22j) 

Code # 2: like normal matrix multiplication

# Python program illustrating
# numpy.inner () method

 

import numpy as geek 

 
# 1D array

vector_a = geek.array ([[ 1 , 4 ], [ 5 , 6 ]]) 

vector_b = geek.array ([[ 2 , 4 ], [ 5 , 2 ]]) 

 

product = geek.inner (vector_a, vector_b) 

print ( "inner Product:" , product) 

 

product = geek.inner (vector_b, vector_a) 

print ( " inner Product: " , product) 

Exit:

 inner Product: [[18 13] [34 37]] inner Product: [[18 34] [13 37]] 




Get Solution for free from DataCamp guru