我們知道在numpy中有四個用于數(shù)組的邏輯判斷函數(shù):
logical_and
logical_or
logical_xor
logical_not
一般而言全蝶,這四個函數(shù)只接受2個邏輯判斷傻昙,那么如何使它接受更多的判斷呢只洒?
使用如下代碼:
import numpy as np
import os
x = np.arange(5)
np.logical_or.reduce([x==1,x==2,x==4])
#后面緊跟3個邏輯判斷
# 除此之外镊靴,還可以使用python自帶的reduce
import functools
functools.reduce(np.logical_or, (x==1,x==2,x==4))