
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Get the Inner product of a One-Dimensional and a Two-Dimensional array 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.arange(2).reshape((1,1,2)) arr2 = np.arange(6).reshape((3,2))
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.arange(2).reshape((1,1,2)) arr2 = np.arange(6).reshape((3,2)) # 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 # Ordinary inner product of vectors for 1-D arrays, in higher dimensions a sum product over the last axes. print("\nResult (Inner Product)...\n",np.inner(arr1, arr2))
Output
Array1... [[[0 1]]] Array2... [[0 1] [2 3] [4 5]] Dimensions of Array1... 3 Dimensions of Array2... 2 Shape of Array1... (1, 1, 2) Shape of Array2... (3, 2) Result (Inner Product)... [[[1 3 5]]]
- Related Articles
- Get the Inner product of two One-Dimensional arrays in Python
- Get the Inner product of two multi-dimensional arrays in Python
- 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 One-Dimensional arrays in Numpy
- Split one-dimensional array into two-dimensional array JavaScript
- Difference Between One-Dimensional (1D) and Two-Dimensional (2D) Array
- Return the inner product of two masked Three Dimensional arrays in Numpy
- Get the inverse of a Four-Dimensional array in Python
- Return the dot product of One-Dimensional vectors in Python
- Compute the bit-wise AND of a One Dimensional and a zero-dimensional array element-wise in Numpy
- Get the Inner product of an array and a scalar in Python
- Return the outer product of two masked One-Dimensional Numpy arrays
- Get the width and height of a three-dimensional array
- Transpose of a two-dimensional array - JavaScript

Advertisements