小编Shi*_*abK的帖子

PyTorch TypeError: new(): 将嵌套列表转换为张量时,数据类型 'str' 无效?

我尝试从嵌套列表创建 Pytorch 张量,但出现这个奇怪的错误

data = pd.read_csv('TrackDataNormalized.csv')

#Get needed columns from csv
X = data.iloc[:, 0]
y = data.iloc[:, 1]

#Split data
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)

#each element in X_train is a list, which is converted to a string when read from a csv, #so we convert it back

X_train = X_train.to_numpy(X_train)
y_train = y_train.to_numpy(y_train)
X_test = X_test.to_numpy(X_test)
y_test = y_test.to_numpy(y_test)

old_train = X_train
X_train = []
for i in range(len(old_train)):
    X_train.append(ast.literal_eval(old_train[i,]))


old_test = X_test
X_test = …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy pandas pytorch

5
推荐指数
0
解决办法
9957
查看次数

标签 统计

arrays ×1

numpy ×1

pandas ×1

python ×1

pytorch ×1