我正在嘗試此頁面的簡單示例
里面說:
arr=np.array([4,7,12])
arr1=np.array([5,9,15])
np.concatenate((arr,arr1))
# Must give array([ 4, 7, 12, 5, 9, 15])
np.concatenate((arr,arr1),axis=1)
#Must give
#[[4,5],[7,9],[12,15]]
# but it gives *** numpy.AxisError: axis 1 is out of bounds for array of dimension 1
為什么這個例子不起作用?
uj5u.com熱心網友回復:
np.vstack是你要找的。請注意最后的轉置,這會將vstack的 2x3 結果轉換為 3x2 陣列。
import numpy as np
arr = np.array([4,7,12])
arr1 = np.array([5,9,15])
a = np.vstack((arr,arr1)).T
print(a)
輸出:
[[ 4 5]
[ 7 9]
[12 15]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/537821.html
標籤:Python数组麻木的
