📜  numpy.outer()函数Python

📅  最后修改于: 2022-05-13 01:54:38.360000             🧑  作者: Mango

numpy.outer()函数Python

numpy.outer()函数计算两个向量的外积。

代码#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)

输出 :

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


代码#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)

输出 :

[[-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.]]