作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我运行我的代码,它在第 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/
我是一名优秀的程序员,十分优秀!