简体   繁体   English

TypeError:ufunc'splaly'不包含带签名匹配类型的循环dtype('S32')dtype('S32')dtype('S32')

[英]TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S32') dtype('S32') dtype('S32')

I am new to coding but I am trying to create a really simple program that will basically plot a line. 我是编码的新手,但我正在尝试创建一个非常简单的程序,它基本上会绘制一条线。 The user will input values for v and a then v and a and x will determine y. 用户将输入v和a然后v的值,a和x将确定y。 I attempted to do this with this: 我试图这样做:

x = np.linspace(0., 9., 10)
a = raw_input('Acceleration =')
v = raw_input('Velocity = ')
y=v*x-0.5*a*x**2.

basically this will represent a parabola where v is velocity, a is acceleration and x is time. 基本上这将代表抛物线,其中v是速度,a是加速度,x是时间。 But, I keep getting this error: 但是,我一直收到这个错误:

TypeError: ufunc 'multiply' did not contain a loop with signature matching types dtype('S32'
) dtype('S32') dtype('S32')

From the documentation of raw_input : raw_input文档

The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. 然后,该函数从输入中读取一行,将其转换为字符串(剥离尾部换行符),然后返回该行。

So what happens is that you try to multiply a string with a float, something like y="3" * x - 0.5 * "3" *x**2 , which is not defined. 所以会发生的是你尝试将一个字符串与一个浮点数相乘,例如y="3" * x - 0.5 * "3" *x**2 ,这是未定义的。

The easiest way to circumvent this is to cast the input string to float first. 避免这种情况的最简单方法是首先将输入字符串转换为float。

x = np.linspace(0., 9., 10)
a = float(raw_input('Acceleration ='))
v = float(raw_input('Velocity = '))
y=v*x-0.5*a*x**2

Mind that if you're using python 3, you'd need to use input instead of raw_input , 请注意,如果您使用的是python 3,则需要使用input而不是raw_input

a = float(input('Acceleration ='))

我最近遇到了这个问题,通过执行以下操作将x的dtype更改为特定的:

x = np.asarray(x, dtype='float64')

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&#39;add&#39;不包含签名匹配类型为dtype(&#39;S32&#39;)dtype(&#39;S32&#39;)dtype(&#39;S32&#39;)的循环 - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S32') dtype('S32') dtype('S32') ufunc 'add' 不包含签名匹配类型 dtype ('S32') ('S32') ('S32') 的循环 - ufunc 'add' did not contain loop with signature matching type dtype ('S32') ('S32') ('S32') Numpy.dot TypeError:根据规则&#39;safe&#39;,无法将数组数据从dtype(&#39;float64&#39;)转换为dtype(&#39;S32&#39;) - Numpy.dot TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe' TypeError: 数组 dtype ('|S32') 和格式说明符 ('%.7f %.7f %.7f %s') 不匹配 - TypeError: Mismatch between array dtype ('|S32') and format specifier ('%.7f %.7f %.7f %s') sklearn.manifold.TSNE TypeError:ufunc&#39;multiply&#39;不包含签名匹配类型的循环(dtype(&#39; - sklearn.manifold.TSNE TypeError: ufunc 'multiply' did not contain a loop with signature matching types (dtype('<U32'), dtype('<U32'))...) 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')) 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') 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’) Python将CSV导入到数组TypeError中:无法根据规则“安全”将数组数据从dtype(&#39;float64&#39;)转换为dtype(&#39;S32&#39;) - Python import CSV into array TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe' 使用matplotlib绘制3d线图。 TypeError:根据规则&#39;safe&#39;,无法将数组数据从dtype(&#39;float64&#39;)转换为dtype(&#39;S32&#39;) - Plotting 3d line graph using matplotlib. TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM