TypeError:ufunc'add'不包含签名匹配类型为(dtype('<U21'),dtype('<U21'))-> dtype('<U21')的循环

时间:2020-02-20 16:51:48

标签: python

我运行我的代码,它在第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()

1 个答案:

答案 0 :(得分:1)

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

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

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