我可能有點困惑。但我想知道 x[2,3] 和 y[2,3,1] 之間有什么區別(相同的陣列但有大小為 1 的額外維度)。
它們是一樣的還是有區別的。
uj5u.com熱心網友回復:
讓我們舉一個 2D 的例子
# shape (2,)
a = np.array([0,1])
# shape (2,1)
b = np.array([[3],[4]])
您可以將其視為a具有 2 列的單行(實際上是一維向量),而將b陣列視為具有一列的 2 行。
讓我們嘗試添加它們:
a a
# addition on a single dimension
# array([0, 2])
b b
# also common dimensions
# array([[6],
# [8]])
a b
# different dimensions with one of common size
# addition will be broadcasted to generate a (2,2) shape
# array([[3, 5],
# [4, 6]])
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/397943.html
