如果兩個數組在公差範圍內按元素方式相等,則numpy.ma.allclose()函數返回True。此函數等效於allclose,不同之處在於,根據masked_equal參數,將掩碼值視為相等(默認值)或不相等。
用法: numpy.ma.allclose(a, b, masked_equal = True, rtol = 1e-05, atol = 1e-08)
參數:
a,b:[數組]要比較的輸入數組。
masked_equal:[布爾,可選]是否認為a和b中的掩碼值相等(真)或不正確(假)。默認情況下,它們被視為相等。
rtol :[float,可選]相對公差。相對差等於rtol * b。默認值為1e-5。
atol :[浮點數,可選]絕對公差。絕對差等於atol。默認值為1e-8。
Return :[bool]如果兩個數組在給定的公差範圍內相等,則返回True,否則返回False。如果任一數組包含NaN,則返回False。
代碼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
相關用法
- Python Wand function()用法及代碼示例
- Python map()用法及代碼示例
- Python hex()用法及代碼示例
- Python dir()用法及代碼示例
- Python sum()用法及代碼示例
- Python ord()用法及代碼示例
- Python id()用法及代碼示例
- Python now()用法及代碼示例
- Python cmp()用法及代碼示例
- Python int()用法及代碼示例
- Python tell()用法及代碼示例
- Python str()用法及代碼示例
- Python oct()用法及代碼示例
- Python property()用法及代碼示例
- Python Wand fx()用法及代碼示例
- Python math.cos()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.ma.allclose() function – Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。