Q1: 在numpy的argmax (argmin)指令中,如果陣列最大值(或最小值)的數字出現在兩個以上的元素,指令只會抓出其中index最小的位置。如果想要抓出所有最大值的位置,是不是有別的指令?
A = np.array([1,2,3,1])
indminA = np.argmin(A) ← smallest index of where minimum of A occur
A1: 先找出最大/小值,用 (A==…).nonzero()找出與最大(小)值相等的所有位置:
minA = np.amin(A)
all_indminA = (A==minA).nonzero()
all_indminA[:] ← indices of where minimum of A occur

Series也類似:

使用isin():

要取得元素 == True的index
原本要寫好幾行:

現在只要一行:
boolAry.nonzero()
輸出: (array([0, 3], dtype=int64),)
需要注意,其為長度1的tuple
boolAry.nonzero()[0] 才是array
pandas如何用 .iloc[bool_list] 取出判斷式為真的那一列?
pandas.Series.str.contains(“Hz”)
處理DataFrame常會用到bool_list
需要取得元素==True的index
可用.nonzero()替代
boolAry:

想取出元素(==True的index)有點特別
boolAry.nonzero():

推薦hahow線上學習python: https://igrape.net/30afN
![Python:如何使用 PyMuPDF (import fitz ) 提取 PDF 文本區塊並存儲為 DataFrame ; text: List[ Tuple[float|str|int] ] = page.get_text(“blocks”) Python:如何使用 PyMuPDF (import fitz ) 提取 PDF 文本區塊並存儲為 DataFrame ; text: List[ Tuple[float|str|int] ] = page.get_text(“blocks”)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250320084417_0_7783bd.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



![使用 Python 檢驗字符串格式:掌握正則表達式(Regular Expression)的起始^與終止$符號, pattern = r’^GATR[0-9]{4}$’ 使用 Python 檢驗字符串格式:掌握正則表達式(Regular Expression)的起始^與終止$符號, pattern = r’^GATR[0-9]{4}$’](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2024/07/20240712093637_0.png?quality=90&zoom=2&ssl=1&resize=350%2C233)


![Python: 資料格式如 List[dict],如何快速將SN加入每一個dict中,以利Excel輸出?如何解包dict? **dict ; 將List[dict]的資料轉為pandas.DataFrame 長什麼樣子? Python: 資料格式如 List[dict],如何快速將SN加入每一個dict中,以利Excel輸出?如何解包dict? **dict ; 將List[dict]的資料轉為pandas.DataFrame 長什麼樣子?](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2024/02/20240208093926_0.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件) Python爬蟲:BeautifulSoup的 .find_all() 與 .find() 與 .select(‘標籤名[屬性名1=”屬性值1″][屬性名2=”屬性值2″]’) ; from bs4 import BeautifulSoup ; Live Server(可以預覽HTML的VS Code套件)](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2025/03/20250330190318_0_925655.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言