📜  Python中的numpy.less_equal

📅  最后修改于: 2020-06-17 04:38:07             🧑  作者: Mango

numpy.less_equal(x1, x2[, out]) :检查x1是否<= x2。

参数:

x1,x2:[array_like]输入数组。如果x1.shape!= x2.shape,则它们必须是
             可广播到相同的形状
out:[ndarray,boolean]布尔数组,如果x1和x2是标量,则为单个布尔。

返回:

布尔数组,指示结果,x1是否小于x2

 

代码1: 

# Python程序说明numpy.less_equal()方法 
   
import numpy as geek  
  
a  = geek.less_equal([8., 2.], [5., 3.]) 
print("less_equal() : \n", a, "\n") 
  
b = geek.less_equal([2, 2], [[1, 3],[1, 4]]) 
print("less_equal() : \n", b, "\n") 
  
a = geek.array([4,3]) 
b = geek.array([6,2]) 
  
print("a是否小于等于b: ", a <= b) 

输出: 

less_equal() : 
 [False  True] 

less_equal() : 
 [[False  True]
 [False  True]] 

a是否小于等于b :  [ True False]

代码2: 

# Python程序说明numpy.less_equal()方法 
    
import numpy as geek  
   
 
a = geek.array([100j,7]) 
b = geek.array([1,2]) 
   
print("比较复数和整数 : ", a <= b) 
  
d  = geek.less_equal(a, b) 
print("\n 比较复数和整数  .less_equal() : ", d) 

输出: 

比较复数和整数 :  [ True False]

 比较复数和整数  .less_equal() :  [ True False]

代码3: 

# Python程序说明numpy.less_equal()方法 
    
import numpy as geek  
  
# 这里我们将Float与int值进行比较 
a = geek.array([1.1, 1]) 
b = geek.array([1, 2]) 
  
print("比较float和int : ", a <= b) 
  
d  = geek.less_equal(a, b) 
print("\n 使用.less_equal()比较float和int : ", d) 

输出: 

比较float和int :  [False  True]

 使用.less_equal()比较float和int :  [False  True]