[英]Python - ValueError: operands could not be broadcast together with shapes
[英]ValueError: operands could not be broadcast together with shapes (0,) (784,)
我有一個腳本來從圖像創建一個 pickle 文件。 在轉儲之前,我正在像這樣規范化圖像:
mu = np.mean(all_data.astype(np.float32), 0)
print("mu:", mu)
sigma = np.std(all_data.astype(np.float32), 0)
for device_id in range(400):
X_train[device_id] = np.array(X_train[device_id])
X_test[device_id] = np.array(X_test[device_id])
for device_id in range(400):
X_train[device_id] = (X_train[device_id].astype(np.float32) - mu) / (sigma + 0.001)
X_test[device_id] = (X_test[device_id].astype(np.float32) - mu) / (sigma + 0.001)
X_train[device_id]=X_train[device_id].tolist()
X_test[device_id] = X_test[device_id].tolist()
return X_train, y_train, X_test, y_test
當我運行腳本時,出現以下錯誤:
File "generate_data_mata_learning.py", line 80, in generate_dataset
X_train[device_id] = (X_train[device_id].astype(np.float32) - mu) / (sigma + 0.001)
ValueError: operands could not be broadcast together with shapes (0,) (784,)
我猜這是由 numpy 數組引起的。 但是找不到解決辦法。 任何幫助,將不勝感激。
根據錯誤消息operands could not be broadcast together with shapes (0,) (784,)
, X_train[device_id]
或mu
可能為空。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.