Python邏輯運算子: and or xor(^) not:
對布林值做and or xor(^) not有何效果?
numpy.bool_ (尾巴有_):

尾巴無_的np.bool 已廢棄:
DeprecationWarning: `np.bool` is a deprecated alias for the builtin `bool`. To silence this warning, use `bool` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.bool_` here.
Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations
np.bool(True)

對於np.bool_ 做加法等效於or:

1+1=2 ; bool(2)=True
1+0=1 ; bool(1)=True
0+1=1 ; bool(1)=True
0+0=0 ; bool(0)=False
三種情況皆為True,
只有一種情況False
跟or一樣(只有兩邊都False
才會return False)
bool(任何非0的數字)皆為True

bool() 空list: [],空tuple: (),
空dict: {},空set: set(), 空字串: “”
皆為False:

對於python內建的bool做加法
等效於對1, 0做加法:

對於np.bool_ 做乘法等效於and:

1*1=1 (布林中1代表True)
1*0=0 (布林中0代表False)
0*1=0 (布林中0代表False)
0*0=0 (布林中0代表False)
三種情況皆為False,
只有一種情況True
跟and一樣(只有兩邊都True
才會return True)
對於np.bool_做除法:

1/1=1.0 (沒有換算成bool的True)
0/1=0.0 (沒有換算成bool的False)
1/0=inf 無限大
0/0=nan (Not a Number)
python內建的True/False 會出現
ZeroDivisionError: division by zero

npTrue/npTrue =1.0 (float64):

numpy.bool_不支援減法:

對於numpy.bool_
not 與 ~同效果:

但對於python內建的bool
not是邏輯運算子
~是對1,0做逐位元運算

推薦hahow線上學習python: https://igrape.net/30afN



![Python Logging 完全指南:從基礎到實戰應用; import logging ; logging.basicConfig(level=logging.INFO, handlers=[ logging.StreamHandler(), logging.FileHandler(‘app.log’, mode=’a’, encoding=’utf-8′)] ) ; inspect.currentframe().f_code.co_name #動態取得funcName Python Logging 完全指南:從基礎到實戰應用; import logging ; logging.basicConfig(level=logging.INFO, handlers=[ logging.StreamHandler(), logging.FileHandler(‘app.log’, mode=’a’, encoding=’utf-8′)] ) ; inspect.currentframe().f_code.co_name #動態取得funcName](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/10/20251021155823_0_c16012.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index) Python: pandas.DataFrame (df) 的取值: df [單一字串] 或df [list_of_strings] 選取一個或多個columns; df [切片] 或 df [bool_Series] 選取多個rows #bool_Series長度同rows, index也需要同df.index ,可以使用.equals() 確認: df.index.equals(mask.index)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/04/20250420212553_0_6fb2c3.png?quality=90&zoom=2&ssl=1&resize=350%2C233)




近期留言