Outer Product Properties | Linear Algebra using Python

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

Prerequisites:

Property 1:

Outer product in linear algebra involves two vectors of any dimension but the order is important. When the order is reversed, the product changes, and the resultant matrix changes.

Syntax:

numpy.outer(Vec_1, Vec_2) != numpy.outer(Vec_2, Vec_1)

Program:

# Linear Algebra Learning Sequence
# Outer Product Property I

import numpy as np

a = np.array([2, 4, 8, 7, 7])
b = np.array([2, 3, 1, 7, 8])

#outer product in both order
opab = np.outer(a,b)
opba = np.outer(b,a)

print('---A---\n', a)
print('\n\n---B---\n', b)
print('\n\nOuter Product as A.B : ', opab)
print('\n\nOuter Product as A.B : ', opba)

Output:

---A---
 [2 4 8 7 7]


---B---
 [2 3 1 7 8]


Outer Product as A.B :  [[ 4  6  2 14 16]
 [ 8 12  4 28 32]
 [16 24  8 56 64]
 [14 21  7 49 56]
 [14 21  7 49 56]]


Outer Product as A.B :  [[ 4  8 16 14 14]
 [ 6 12 24 21 21]
 [ 2  4  8  7  7]
 [14 28 56 49 49]
 [16 32 64 56 56]]

Property 2:

Outer product in linear algebra involves two vectors of any dimension but the order is important. If the first Vector is of M dimension and 2nd of N, then the outer product matrix will have dimension MxN.

Syntax:

[m,n] = numpy.shape(numpy.outer(Vec_1, Vec_2))

Program:

# Linear Algebra Learning Sequence
# Outer Product Property I

import numpy as np

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

#outer product in both order
opab = np.outer(a,b)

dim = np.shape(opab)

print('A : ', a, '\nDimension of first vector :', len(a))
print('B : ', b, '\nDimension of second vector : ', len(b))
print('\n\nOuter Product as A.B : ', opab)
print('Outer product Dimensions : ', dim)

Output:

A :  [ 2  4  8  7  7  9 -6] 
Dimension of first vector : 7
B :  [2 3 1 7 8] 
Dimension of second vector :  5


Outer Product as A.B :  [[  4   6   2  14  16]
 [  8  12   4  28  32]
 [ 16  24   8  56  64]
 [ 14  21   7  49  56]
 [ 14  21   7  49  56]
 [ 18  27   9  63  72]
 [-12 -18  -6 -42 -48]]
Outer product Dimensions :  (7, 5)



Comments and Discussions!

Load comments ↻






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