numpy.equal(arr1,arr2,out = None,where = True,cast ='same_kind',order ='K',dtype = None,ufunc'not_equal'):此邏輯函數檢查arr1 == arr2 elemen-twise。
參數:
-
arr1 :[數組]輸入數組
arr2 :[數組]輸入數組 - out :[ndarray,可選]輸出數組,其尺寸與輸入數組相同,並放置在結果中。
- **kwargs:允許您將關鍵字的可變參數長度傳遞給函數。當我們要處理函數中的命名參數時使用它。
- where :[數組,可選] True值表示在該位置計算通用函數(ufunc),False值表示將值保留在輸出中。
返回:
Returns arr1 == arr2 element-wise
代碼1:
# Python Program illustrating
# numpy.equal() method
import numpy as geek
a = geek.equal([1., 2.], [1., 3.])
print("Check to be Equal:\n", a, "\n")
b = geek.equal([1, 2], [[1, 3],[1, 4]])
print("Check to be Equal:\n", b, "\n")
輸出:
Check to be Equal: [ True False] Check to be Equal: [[ True False] [ True False]]
代碼2:使用.equal()函數比較數據類型
# Python Program illustrating
# numpy.equal() method
import numpy as geek
# Here we will compare Complex values with int
a = geek.array([0 + 1j, 2])
b = geek.array([1,2])
d = geek.equal(a, b)
print("Comparing complex with int using .equal():", d)
輸出:
Comparing complex with int using .equal(): [False True]
代碼3:
# Python Program illustrating
# numpy.not_equal() method
import numpy as geek
# Here we will compare Float with int values
a = geek.array([1.1, 1])
b = geek.array([1, 2])
d = geek.not_equal(a, b)
print("\nComparing float with int using .not_equal():", d)
輸出:
Comparing float with int using .not_equal(): [ True True]
參考文獻:
https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.equal.html
。
相關用法
注:本文由純淨天空篩選整理自Mohit Gupta_OMG 大神的英文原創作品 numpy.equal() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。