Open In App

numpy.outer() function – Python

Improve
Improve
Like Article
Like
Save
Share
Report

numpy.outer() function compute the outer product of two vectors.

Syntax : numpy.outer(a, b, out = None)

Parameters :
a : [array_like] First input vector. Input is flattened if not already 1-dimensional.
b : [array_like] Second input vector. Input is flattened if not already 1-dimensional.
out : [ndarray, optional] A location where the result is stored.

Return : [ndarray] Returns the outer product of two vectors. out[i, j] = a[i] * b[j]

Code #1 :




# Python program explaining
# numpy.outer() function
   
# importing numpy as geek 
import numpy as geek 
  
a = geek.ones(4)
b = geek.linspace(-1, 2, 4)
  
gfg = geek.outer(a, b)
  
print (gfg)


Output :

[[-1.  0.  1.  2.]
 [-1.  0.  1.  2.]
 [-1.  0.  1.  2.]
 [-1.  0.  1.  2.]]

 
Code #2 :




# Python program explaining
# numpy.outer() function
   
# importing numpy as geek 
import numpy as geek 
  
a = geek.ones(5)
b = geek.linspace(-2, 2, 5)
  
gfg = geek.outer(a, b)
  
print (gfg)


Output :

[[-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]
 [-2. -1.  0.  1.  2.]]

Last Updated : 05 May, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads