0
我想向矩陣中添加一個額外的列,以便使用某些機器學習算法預測某些功能。向矩陣添加額外的功能np.Concatenate錯誤:只能將長度爲1的數組轉換爲Python標量
我的trainSet有8899行和11個維度。
我想要做的就是添加額外的維度distance
(見代碼)。
但我得到了一個錯誤:
only length-1 arrays can be converted to Python scalars
temp_train_long/lat
是(8899L,)
X_train = df_train.as_matrix()
temp_train_long=(X_train[:,3] - X_train[:,7])**2#long
temp_train_lat = (X_train[:,4] - X_train[:,8])**2#lat
distance = np.sqrt(temp_train_long + temp_train_lat)
np.concatenate(X_train, distance.T)
不要在long,lat上使用歐幾里德距離。地球不平坦。 –
感謝您的評論,但它不能解決我的問題 –