numpy.bitwise_or()function用於計算兩個數組元素的按位或。此函數計算輸入數組中整數的基礎二進製表示的按位或。
用法: numpy.bitwise_or(arr1, arr2, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None, ufunc ‘bitwise_or’)
參數:
arr1 : [數組]輸入數組。
arr2 : [數組]輸入數組。
out : [ndarray,可選]將結果存儲到的位置。
->如果提供,則必須具有廣播輸入的形狀。
->如果未提供或沒有,則返回新分配的數組。
** kwargs:允許您將關鍵字的可變參數長度傳遞給函數。當我們要處理函數中的命名參數時使用它。
where : [數組,可選] True值表示在該位置計算通用函數(ufunc),False值表示將值保留在輸出中。
返回:[ndarray或標量]結果。如果x1和x2均為標量,則為標量。
代碼1:工作
# Python program explaining
# bitwise_or() function
import numpy as geek
in_num1 = 10
in_num2 = 11
print ("Input number1 : ", in_num1)
print ("Input number2 : ", in_num2)
out_num = geek.bitwise_or(in_num1, in_num2)
print ("bitwise_or of 10 and 11 : ", out_num)
輸out :
Input number1 : 10 Input number2 : 11 bitwise_or of 10 and 11 : 11
代碼2:
# Python program explaining
# bitwise_or() function
import numpy as geek
in_arr1 = [2, 8, 125]
in_arr2 = [3, 3, 115]
print ("Input array1 : ", in_arr1)
print ("Input array2 : ", in_arr2)
out_arr = geek.bitwise_or(in_arr1, in_arr2)
print ("Output array after bitwise_or: ", out_arr)
輸out :
Input array1 : [2, 8, 125] Input array2 : [3, 3, 115] Output array after bitwise_or: [ 3 11 127]
代碼3:
# Python program explaining
# bitwise_or() function
import numpy as geek
in_arr1 = [True, False, True, False]
in_arr2 = [False, False, True, True]
print ("Input array1 : ", in_arr1)
print ("Input array2 : ", in_arr2)
out_arr = geek.bitwise_or(in_arr1, in_arr2)
print ("Output array after bitwise_or: ", out_arr)
輸out :
Input array1 : [True, False, True, False] Input array2 : [False, False, True, True] Output array after bitwise_or: [ True False True True]
相關用法
注:本文由純淨天空篩選整理自jana_sayantan大神的英文原創作品 numpy.bitwise_or() in Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。