简体   繁体   English

类型错误:ufunc &#39;add&#39; 不包含具有签名匹配类型的循环 (dtype(&#39; <U21'), dtype('<U21')) -> 数据类型(&#39;

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

I run my code and it throw a error in line 79:我运行我的代码,它在第 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()

The likely situation is that elem[0] in line 79 isn't a string, but rather is a numeric type from deep in numpy.可能的情况是第 79 行中的elem[0]不是字符串,而是来自 numpy 深处的数字类型。

Try changing lines 78 and 79 to this instead:尝试将第 78 行和第 79 行改为:

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

TypeError: ufunc 'add' 不包含签名匹配类型 dtype(' <u1') dtype('<u1') dtype('<u1')< div><div id="text_translate"><p> 我是 Python 用户的初学者。 当我尝试在下面编写代码时发生错误</p><pre>import numpy as np np.array(['a', 'b', 'c']) + np.array(['d','e', 'f'])</pre><pre> TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('&lt;U1') dtype('&lt;U1') dtype('&lt;U1')</pre><p> 所以我尝试设置dtype = '&lt;U1' ,但它没有用</p><pre>import numpy as np np.array(['a', 'b', 'c'], dtype='&lt;U1') + np.array(['d','e', 'f'], dtype='&lt;U1')</pre><p> 如何无错误地连接那些 np.arrays ?</p></div></u1')> - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1')

转换 unix 时间戳的 np.array (dtype ' <u21') to np.datetime64< div><div id="text_translate"><p> 我正在寻找处理大量数据,因此我对计算以下内容的最快方法感兴趣:</p><p> 我将以下 np.array 作为 np.ndarray 的一部分,我想将其从“&lt;U21”转换为“np.datetime64”(毫秒)。</p><p> 当我在一个条目上执行以下代码时,它可以工作:</p><pre> tmp_array[:,0][0].astype(int).astype('datetime64[ms]')</pre><p> 结果:numpy.datetime64('2019-10-09T22:54:00.000')</p><p> 当我像这样在子数组上执行相同的操作时:</p><pre> tmp_array[:,0] = tmp_array[:,0].astype(int).astype('datetime64[ms]')</pre><p> 我总是收到以下错误:</p><pre> RuntimeError: The string provided for NumPy ISO datetime formatting was too short, with length 21</pre><p> numpy 版本 1.22.4</p><pre> array(['1570661640000', '1570661700000', '1570661760000'],dtype='&lt;U21')</pre></div></u21')> - Converting np.array of unix timestamps (dtype '<U21') to np.datetime64

UFuncTypeError:ufunc 'clip' 不包含具有签名匹配类型的循环(dtype(' <u32’), dtype(‘<u32’), dtype(‘<u32’)) -> dtype(' <u32’)< div><div id="text_translate"><p> 我使用 Deep Pavlov 框架与 Bert 分类器一起工作,只是因为我需要预测人员的语言是俄语。 基本上,我正在尝试解决多类分类问题。 根据 Deep Pavlov,我们可以轻松地更改配置文件上的一些配置。 我拿了这个配置文件<a href="https://github.com/deepmipt/DeepPavlov/blob/master/deeppavlov/configs/classifiers/rusentiment_convers_bert.json" rel="nofollow noreferrer">https://github.com/deepmipt/DeepPavlov/blob/master/deeppavlov/configs/classifiers/rusentiment_convers_bert.json</a>并训练它,结果我花了大约 13 个小时才完成它我的 model 过拟合。</p><p> 我做了一些改变,尤其是这些:</p><pre> "weight_decay_rate": 0.001, "learning_rate_drop_patience": 1, "learning_rate_drop_div": 2.0, "load_before_drop": True, "min_learning_rate": 1e-03, "attention_probs_keep_prob": 0.5, "hidden_keep_prob": 0.5,</pre><p> 另外,我增加了批量大小,之前是 16:</p><pre> "batch_size": 32</pre><p> 并添加了一些指标:</p><pre> "log_loss", "matthews_correlation",</pre><p> 还将validation_patience更改为1并添加了tensorboard func</p><pre> "validation_patience": 1, "tensorboard_log_dir": "logs/",</pre><p> 就是这样。 这些是我对 model 所做的所有更改,当我尝试训练我的 model 时,它给了我以下错误:</p><pre> UFuncTypeError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 60 try: ---&gt; 61 return bound(*args, **kwds) 62 except TypeError: 15 frames UFuncTypeError: ufunc 'clip' did not contain a loop with signature matching types (dtype('&lt;U32'), dtype('&lt;U32'), dtype('&lt;U32')) -&gt; dtype('&lt;U32') During handling of the above exception, another exception occurred: UFuncTypeError Traceback (most recent call last) &lt;__array_function__ internals&gt; in clip(*args, **kwargs) /usr/local/lib/python3.7/dist-packages/numpy/core/_methods.py in _clip_dep_invoke_with_casting(ufunc, out, casting, *args, **kwargs) 83 # try to deal with broken casting rules 84 try: ---&gt; 85 return ufunc(*args, out=out, **kwargs) 86 except _exceptions._UFuncOutputCastingError as e: 87 # Numpy 1.17.0, 2019-02-24 UFuncTypeError: ufunc 'clip' did not contain a loop with signature matching types (dtype('&lt;U32'), dtype('&lt;U32'), dtype('&lt;U32')) -&gt; dtype('&lt;U32')</pre><p> 起初,我认为它与数据集有关,但是,我没有更改我的数据集,并且在我第一次训练这个 model 时它已经运行。 </p></div></u32’)<></u32’),> - UFuncTypeError: ufunc ‘clip’ did not contain a loop with signature matching types (dtype(‘<U32’), dtype(‘<U32’), dtype(‘<U32’)) -> dtype(‘<U32’)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError: ufunc 'add' 不包含签名匹配类型 dtype(' <u1') dtype('<u1') dtype('<u1')< div><div id="text_translate"><p> 我是 Python 用户的初学者。 当我尝试在下面编写代码时发生错误</p><pre>import numpy as np np.array(['a', 'b', 'c']) + np.array(['d','e', 'f'])</pre><pre> TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('&lt;U1') dtype('&lt;U1') dtype('&lt;U1')</pre><p> 所以我尝试设置dtype = '&lt;U1' ,但它没有用</p><pre>import numpy as np np.array(['a', 'b', 'c'], dtype='&lt;U1') + np.array(['d','e', 'f'], dtype='&lt;U1')</pre><p> 如何无错误地连接那些 np.arrays ?</p></div></u1')> - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1') 转换 unix 时间戳的 np.array (dtype ' <u21') to np.datetime64< div><div id="text_translate"><p> 我正在寻找处理大量数据,因此我对计算以下内容的最快方法感兴趣:</p><p> 我将以下 np.array 作为 np.ndarray 的一部分,我想将其从“&lt;U21”转换为“np.datetime64”(毫秒)。</p><p> 当我在一个条目上执行以下代码时,它可以工作:</p><pre> tmp_array[:,0][0].astype(int).astype('datetime64[ms]')</pre><p> 结果:numpy.datetime64('2019-10-09T22:54:00.000')</p><p> 当我像这样在子数组上执行相同的操作时:</p><pre> tmp_array[:,0] = tmp_array[:,0].astype(int).astype('datetime64[ms]')</pre><p> 我总是收到以下错误:</p><pre> RuntimeError: The string provided for NumPy ISO datetime formatting was too short, with length 21</pre><p> numpy 版本 1.22.4</p><pre> array(['1570661640000', '1570661700000', '1570661760000'],dtype='&lt;U21')</pre></div></u21')> - Converting np.array of unix timestamps (dtype '<U21') to np.datetime64 ufunc&#39;add&#39;不包含签名匹配类型为dtype(&#39; - ufunc 'add' did not contain a loop with signature matching types dtype('<U23') dtype('<U23') dtype('<U23') TypeError:ufunc&#39;add&#39;不包含签名匹配类型为dtype(&#39;的循环 - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U72') dtype('<U72') dtype('<U72') Keras PREDICTION抛出&#39;TypeError:ufunc&#39;add&#39;不包含签名匹配类型为dtype(&#39;的循环 - Keras PREDICTION throws 'TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U4') dtype('<U4') dtype('<U4')' 类型错误:ufunc &#39;add&#39; 不包含签名匹配类型 dtype(&#39; - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U78') dtype('<U78') dtype('<U78' TypeError:ufunc&#39;add&#39;不包含签名匹配类型为dtype(&#39;的循环 - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32') Python:ufunc 'add' 不包含签名匹配类型 dtype('S21') dtype('S21') dtype('S21') 的循环 - Python: ufunc 'add' did not contain a loop with signature matching types dtype('S21') dtype('S21') dtype('S21') Scikit-Learn(类型错误:ufunc &#39;subtract&#39; 不包含签名匹配类型 dtype(&#39; - Scikit-Learn (TypeError: ufunc 'subtract' did not contain a loop with signature matching types dtype('<U32') dtype('<U32') dtype('<U32')) UFuncTypeError:ufunc 'clip' 不包含具有签名匹配类型的循环(dtype(' <u32’), dtype(‘<u32’), dtype(‘<u32’)) -> dtype(' <u32’)< div><div id="text_translate"><p> 我使用 Deep Pavlov 框架与 Bert 分类器一起工作,只是因为我需要预测人员的语言是俄语。 基本上,我正在尝试解决多类分类问题。 根据 Deep Pavlov,我们可以轻松地更改配置文件上的一些配置。 我拿了这个配置文件<a href="https://github.com/deepmipt/DeepPavlov/blob/master/deeppavlov/configs/classifiers/rusentiment_convers_bert.json" rel="nofollow noreferrer">https://github.com/deepmipt/DeepPavlov/blob/master/deeppavlov/configs/classifiers/rusentiment_convers_bert.json</a>并训练它,结果我花了大约 13 个小时才完成它我的 model 过拟合。</p><p> 我做了一些改变,尤其是这些:</p><pre> "weight_decay_rate": 0.001, "learning_rate_drop_patience": 1, "learning_rate_drop_div": 2.0, "load_before_drop": True, "min_learning_rate": 1e-03, "attention_probs_keep_prob": 0.5, "hidden_keep_prob": 0.5,</pre><p> 另外,我增加了批量大小,之前是 16:</p><pre> "batch_size": 32</pre><p> 并添加了一些指标:</p><pre> "log_loss", "matthews_correlation",</pre><p> 还将validation_patience更改为1并添加了tensorboard func</p><pre> "validation_patience": 1, "tensorboard_log_dir": "logs/",</pre><p> 就是这样。 这些是我对 model 所做的所有更改,当我尝试训练我的 model 时,它给了我以下错误:</p><pre> UFuncTypeError Traceback (most recent call last) /usr/local/lib/python3.7/dist-packages/numpy/core/fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 60 try: ---&gt; 61 return bound(*args, **kwds) 62 except TypeError: 15 frames UFuncTypeError: ufunc 'clip' did not contain a loop with signature matching types (dtype('&lt;U32'), dtype('&lt;U32'), dtype('&lt;U32')) -&gt; dtype('&lt;U32') During handling of the above exception, another exception occurred: UFuncTypeError Traceback (most recent call last) &lt;__array_function__ internals&gt; in clip(*args, **kwargs) /usr/local/lib/python3.7/dist-packages/numpy/core/_methods.py in _clip_dep_invoke_with_casting(ufunc, out, casting, *args, **kwargs) 83 # try to deal with broken casting rules 84 try: ---&gt; 85 return ufunc(*args, out=out, **kwargs) 86 except _exceptions._UFuncOutputCastingError as e: 87 # Numpy 1.17.0, 2019-02-24 UFuncTypeError: ufunc 'clip' did not contain a loop with signature matching types (dtype('&lt;U32'), dtype('&lt;U32'), dtype('&lt;U32')) -&gt; dtype('&lt;U32')</pre><p> 起初,我认为它与数据集有关,但是,我没有更改我的数据集,并且在我第一次训练这个 model 时它已经运行。 </p></div></u32’)<></u32’),> - UFuncTypeError: ufunc ‘clip’ did not contain a loop with signature matching types (dtype(‘<U32’), dtype(‘<U32’), dtype(‘<U32’)) -> dtype(‘<U32’)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM