'and' (boolean) vs '&' (bitwise) - Why difference in behavior with lists vs numpy arrays?
问题 What explains the difference in behavior of boolean and bitwise operations on lists vs NumPy arrays? I\'m confused about the appropriate use of & vs and in Python, illustrated in the following examples. mylist1 = [True, True, True, False, True] mylist2 = [False, True, False, True, False] >>> len(mylist1) == len(mylist2) True # ---- Example 1 ---- >>> mylist1 and mylist2 [False, True, False, True, False] # I would have expected [False, True, False, False, False] # ---- Example 2 ---- >>>