请求的数组在 1 维后具有不均匀的形状。检测到的形状是 (33,) + 不均匀部分
The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (33,) + inhomogeneous part
我卡在了将列表转换为 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
意思是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。它们不能组合成一个数组,因为“列”维度不匹配。
我卡在了将列表转换为 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
意思是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。它们不能组合成一个数组,因为“列”维度不匹配。