gpt4 book ai didi

python - 类型错误 : ufunc 'add' did not contain a loop with signature matching types (dtype (' dtype ('
转载 作者:行者123 更新时间:2023-12-01 06:21:45 44 4
gpt4 key购买 nike

我运行我的代码,它在第 79 行抛出错误:

numpy.core._exceptions.UFuncTypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U21'), dtype('<U21')) -> dtype('<U21').

大家都知道如何解决请帮助我。太感谢了。我的代码:

68 multi_df = pd.read_csv(FLAGS.VoTT_csv)
69 labels = multi_df["label"].unique()
70 labeldict = dict(zip(labels, range(len(labels))))
71 multi_df.drop_duplicates(subset=None, keep="first", inplace=True)
72 train_path = FLAGS.VoTT_Folder
73 convert_vott_csv_to_yolo(
74 multi_df, labeldict, path=train_path, target_name=FLAGS.YOLO_filename
75 )

76 file = open(classes_filename, "w")

77 SortedLabelDict = sorted(labeldict.items(), key=lambda x: x[1])
78 for elem in SortedLabelDict:
79 file.write(elem[0] + "\n")
80 file.close()

最佳答案

可能的情况是第 79 行中的 elem[0] 不是字符串,而是 numpy 深处的数字类型。

尝试将第 78 行和 79 行更改为:

for elem in SortedLabelDict:
file.write(str(elem[0]) + "\n")

关于python - 类型错误 : ufunc 'add' did not contain a loop with signature matching types (dtype ('<U21' ), dtype ('<U21' )) -> dtype ('<U21' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60324967/

44 4 0

Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com