我堅持將串列轉換為numpy。轉換串列大小為 (33, n, 428)。N 是隨機差異,我不知道數字是如何組成的。這是錯誤。
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
C:\Users\HILAB_~1\AppData\Local\Temp/ipykernel_22960/872733971.py in <module>
----> 1 X_train = np.array(X_train, dtype=np.float64)
2
3 for epoch in range(EPOCH):
4 X_train_ten, y_train_ten = Variable(torch.from_numpy(X_train)), Variable(torch.tensor(y_train, dtype=torch.float32, requires_grad=True))
5 print(X_train_ten.size())
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (33,) inhomogeneous part.
問題代碼在這里。
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.3, random_state=42, shuffle=True
)
print("[SIZE]\t\tTrain X size : {}, Train y size : {}\n\t\tTest X size : {}, Test y size : {}"\
.format(len(X_train), len(y_train), len(X_test), len(y_test)))
train_dataloadloader = DataLoader(X_train)
test_dataloader = DataLoader(X_test)
X_train = np.array(X_train, dtype=np.float64)
我不明白錯誤是什么意思。請幫忙。感謝:D
uj5u.com熱心網友回復:
這意味著無論序列X包含什么,它們的長度都不相同。你可以檢查{len(e) for e in X); 這是在 中找到的所有不同長度的集合X。
考慮以下示例:
>>> import numpy as np
>>> x = [[1, 2], [2, 3, 4]]
>>> np.array(x, dtype=np.float64)
[...]
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (2,) inhomogeneous part.
在這里,串列x包含另外兩個串列,一個長度為 2,另一個長度為 3。由于“列”維度不匹配,因此它們不能組合成一個陣列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/485476.html
下一篇:如何找出n年的最大百分比變化?
