- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Get the Inner product of two arrays in Python

To get the Inner product of two arrays, use the numpy.inner() method in Python. Ordinary inner product of vectors for 1-D arrays, in higher dimensions a sum product over the last axes. The parameters are 1 and b, two vectors. If a and b are nonscalar, their last dimensions must match.

## Steps

At first, import the required libraries −

import numpy as np

Creating two numpy One-Dimensional array using the array() method −

arr1 = np.array([5, 10, 15]) arr2 = np.array([20, 25, 30])

Display the arrays −

print("Array1...\n",arr1) print("\nArray2...\n",arr2)

Check the Dimensions of both the arrays −

print("\nDimensions of Array1...\n",arr1.ndim) print("\nDimensions of Array2...\n",arr2.ndim)

Check the Shape of both the arrays −

print("\nShape of Array1...\n",arr1.shape) print("\nShape of Array2...\n",arr2.shape)

To get the Inner product of two arrays, use the numpy.inner() method −

print("\nResult (Inner Product)...\n",np.inner(arr1, arr2))

## Example

import numpy as np # Creating two numpy One-Dimensional array using the array() method arr1 = np.array([5, 10, 15]) arr2 = np.array([20, 25, 30]) # Display the arrays print("Array1...\n",arr1) print("\nArray2...\n",arr2) # Check the Dimensions of both the arrays print("\nDimensions of Array1...\n",arr1.ndim) print("\nDimensions of Array2...\n",arr2.ndim) # Check the Shape of both the arrays print("\nShape of Array1...\n",arr1.shape) print("\nShape of Array2...\n",arr2.shape) # To get the Inner product of two arrays, use the numpy.inner() method in Python print("\nResult (Inner Product)...\n",np.inner(arr1, arr2))

## Output

Array1... [ 5 10 15] Array2... [20 25 30] Dimensions of Array1... 1 Dimensions of Array2... 1 Shape of Array1... (3,) Shape of Array2... (3,) Result (Inner Product)... 800

- Related Questions & Answers
- Get the Inner product of two multi-dimensional arrays in Python
- Get the Inner product of two One-Dimensional arrays in Python
- Return the inner product of two masked arrays in Numpy
- Get the Kronecker product of two arrays in Python
- Get the Outer product of two arrays in Python
- Get the Outer product of two multidimensional arrays in Python
- Return the inner product of two masked One-Dimensional arrays in Numpy
- Return the inner product of two masked Three Dimensional arrays in Numpy
- Get the Outer product of two One-Dimensional arrays in Python
- Get the Kronecker product of two One-Dimensional Arrays in Python
- Return the inner product of two masked arrays with different shapes in Numpy
- Get the Kronecker product of two arrays with different dimensions in Python
- Get the Inner product of a One-Dimensional and a Two-Dimensional array in Python
- Get the Inner product of an array and a scalar in Python
- Return the cross product of two (arrays of) vectors in Python

Advertisements