小编Pet*_*ves的帖子

我该如何制作一大串花车?

我正在创建一个包含大量数字数据的arff文件.既然我的特征向量非常大,我最终得到了这样的代码

with(file,'w') as myfile:
    s = number + ","
    s += number + ","
    s += number + ","
    s += number + ","
    ...
    myfile.write(s)
Run Code Online (Sandbox Code Playgroud)

由于我对Python很陌生,我显然忘记了Python似乎不允许将浮点数连接到这样的字符串并给出以下错误.

unsupported operand type(s) for +: 'numpy.float64' and 'str'
Run Code Online (Sandbox Code Playgroud)

那么一个更有经验的python程序员如何处理这个问题,或者我真的必须将所有这些数字转换成这样的字符串

with(file,'w') as myfile:
    s = str(number) + ","
    s += str(number) + ","
    s += str(number) + ","
    s += str(number) + ","
    ...
    myfile.write(s)
Run Code Online (Sandbox Code Playgroud)

python concatenation

2
推荐指数
1
解决办法
42
查看次数

标签 统计

concatenation ×1

python ×1