np.newaxis是NumPy中的一個非常有用的工具,
它可以用來增加陣列的維度。
它可以在任何位置插入一個新的維度,
以便更方便地進行數據操作。
下面是一個簡單的示範,
展示如何使用 np.newaxis 來增加一個維度:
import numpy as np
# 創建一個形狀為 (3,) 的一維陣列
x = np.array([1, 2, 3])
# 顯示原始陣列的形狀
print(“x的形狀:”, x.shape)
# 使用 np.newaxis 增加一個新的維度
y = x[:, np.newaxis]
# 顯示新陣列的形狀
print(“y的形狀:”, y.shape)
# 顯示兩個陣列
print(“x:”, x)
print(“y:”, y)
![Python: 如何使用numpy.newaxis 增加資料的維度? y = x[:, np.newaxis] - 儲蓄保險王](https://savingking.com.tw/wp-content/uploads/2023/03/20230313184351_57.png)
推薦hahow線上學習python: https://igrape.net/30afN



![Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身? Python 讀取 DOCX 圖片關聯:qn+find/findall 與 XPath 的實戰對照 from lxml import etree ; from docx.oxml.ns import qn; lxml.etree._Element.findall( f”.//{ qn(‘a:blip’) }” ) ; .get( qn(“r:embed”) ) #獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’) ; lxml.etree._Element.xpath( “//a:blip/@r:embed”, namespaces = NS) #/@r:embed = 獲取 屬性名 ‘r:embed’ 的 屬性值(如: ‘rId4’),使用.findall() 要先.findall()獲取List[_Element],再迴圈_Element.get()獲取屬性值, .xpath() 第一個參數path 使用”//a:blip/@r:embed” ,可直接獲取屬性值(List[str]如: [‘rId4’, ‘rId5’]) ; 如何對docx真實移除圖片瘦身?](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2025/11/20251119130848_0_3fbf6b.png?quality=90&zoom=2&ssl=1&resize=350%2C233)






近期留言