📜  numpy.ma.allclose()函数– Python

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

numpy.ma.allclose()函数– Python

numpy.ma.allclose()如果两个数组在容差范围内按元素相等,则函数返回 True。此函数等效于 allclose,但屏蔽值被视为相等(默认)或不相等,具体取决于 masked_equal 参数。

代码#1:

# Python program explaining
# numpy.ma.allclose() function
   
# importing numpy as geek 
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
    
a = geek.ma.array([1e10, 1e-8, 42.0], mask = [0, 0, 1])
  
b = geek.ma.array([1.00001e10, 1e-9, -42.0], mask = [0, 0, 1])
  
gfg = geek.ma.allclose(a, b)
  
print (gfg)

输出 :

True


代码#2:

# Python program explaining
# numpy.ma.allclose() function
   
# importing numpy as geek 
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
    
a = geek.ma.array([1e10, 1e-8, 42.0], mask = [0, 0, 1])
  
b = geek.ma.array([1.00001e10, 1e-9, -42.0], mask = [0, 0, 1])
  
gfg = geek.ma.allclose(a, b, masked_equal = False)
  
print (gfg)

输出 :

False