Outer Product of Vectors | Linear Algebra using Python

Linear Algebra using Python | Outer Product of Vectors: Here, we are going to learn about the outer product of vectors and its implementation in Python.
Submitted by Anuj Singh, on June 08, 2020

Prerequisites:

Learn: how to code for outer product of two vectors using am inbuilt function in numpy library?

Syntax:

numpy.outer(Vec_1, Vec_2)

Python code for outer product of vectors

# Linear Algebra Learning Sequence
# Outer Product

import numpy as np

a = np.array([2,3,4,1])
b = np.array([5,4,-6,45,7])

outpro = np.outer(a,b)

print('Vector A : ', a)
print('Vector B : ', b)
print('Outer product of Vector A and Vector B :', outpro)

Output:

Vector A :  [2 3 4 1]
Vector B :  [ 5  4 -6 45  7]
Outer product of Vector A and Vector B : [[ 10   8 -12  90  14]
 [ 15  12 -18 135  21]
 [ 20  16 -24 180  28]
 [  5   4  -6  45   7]]


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.