程式碼:
a = 1
lsta = list(a)
print(lsta,type(lsta),len(lsta))
輸出:
Traceback (most recent call last):
File “C:\Python\Radar_20221005\untitled1.py”, line 3, in <module>
lsta = list(a)
TypeError: ‘int’ object is not iterable
int無法取list()
如果取array()呢?
程式碼:
import numpy as np
a = 1
arya = np.array(a)
print(arya, type(arya), len(arya))
輸出:
Traceback (most recent call last):
File “C:\Python\Radar_20221005\untitled1.py”, line 7, in <module>
print(arya,type(arya),len(arya))
TypeError: len() of unsized object
int可以取array(),
只是長度0 (不要誤會長度1)
所以取len()時錯誤
empty list: []長度也是0
去掉len()

3(1+2)的左右邊沒有[ ] 包覆
type為ndarray (0-dimensional)
用法同int
numpy官網:

2D array的運算:

推薦hahow線上學習python: https://igrape.net/30afN
![Python 如何用pandas.Series.nsmallest() 找到n個與target差距最小的index?再從中找到距離idxmax最近的index?避免誤抓sidelobes的index? targetIdx = (serMean-target_value).abs().nsmallest(n).index.tolist() ;Series切片: .loc[標籤名1:標籤名2] (會含標籤名2) ; .iloc[位置1:位置2] (不含位置2) Python 如何用pandas.Series.nsmallest() 找到n個與target差距最小的index?再從中找到距離idxmax最近的index?避免誤抓sidelobes的index? targetIdx = (serMean-target_value).abs().nsmallest(n).index.tolist() ;Series切片: .loc[標籤名1:標籤名2] (會含標籤名2) ; .iloc[位置1:位置2] (不含位置2)](https://i1.wp.com/savingking.com.tw/wp-content/uploads/2023/02/20230222082954_53.png?quality=90&zoom=2&ssl=1&resize=350%2C233)



![Python: 如何將pandas.DataFrame從寬資料轉為長資料? df_melt = pd.melt(df, id_vars=[‘name’, ‘gender’], var_name=’time’, value_name=’score’) ; seaborn繪圖 Python: 如何將pandas.DataFrame從寬資料轉為長資料? df_melt = pd.melt(df, id_vars=[‘name’, ‘gender’], var_name=’time’, value_name=’score’) ; seaborn繪圖](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230302152215_95.png?quality=90&zoom=2&ssl=1&resize=350%2C233)
![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)

]*>.*?底下插入一個圖檔.*?</w:p>’, flags = re.DOTALL) ; new_xml, n = pattern.subn(”, xml, count=1)' title='Python正則替換:全面掌握 re.sub 與 re.subn 的差異與實戰 #substitute(替換); . 預設匹配「除\n以外的任意單一字元」; pattern = re.compile(r'<w:p[^>]*>.*?底下插入一個圖檔.*?</w:p>’, flags = re.DOTALL) ; new_xml, n = pattern.subn(”, xml, count=1)' loading='lazy' width=350 height=233 />

近期留言