Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: ufunc 'add' did not contain a loop with signature matching types (dtype('<U21'), dtype('<U21')) -> dtype('<U21')

Tags:

python

I run my code and it throw a error in line 79:

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

Everybody know how to fix please help me. Thank you so much. My code:

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()
like image 912
HTD Avatar asked Dec 12 '25 19:12

HTD


1 Answers

The likely situation is that elem[0] in line 79 isn't a string, but rather is a numeric type from deep in numpy.

Try changing lines 78 and 79 to this instead:

for elem in SortedLabelDict:
  file.write(str(elem[0]) + "\n")
like image 133
Daniel Martin Avatar answered Dec 14 '25 10:12

Daniel Martin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!