简体   繁体   English

ufunc 'add' 不包含签名匹配类型 dtype 的循环

[英]ufunc 'add' did not contain a loop with signature matching types dtype

Why do I get this error?为什么我会收到这个错误?

ufunc 'add' did not contain a loop with signature matching types dtype ufunc 'add' 不包含签名匹配类型 dtype 的循环

The code:编码:

cols = df.columns.tolist()
cols = np.array (cols)
cols2 = cols[:17] + cols[19:22] + cols [18]

Thanks!谢谢!

There are 2 issues有2个问题

  • operator + , when used on numpy array, is interpreted as numerical addition, not list concatenation, thus the error about the matching dtype. operator + ,当在numpy数组上使用时,被解释为数字加法,而不是列表连接,因此是关于匹配 dtype 的错误。 Instead of addition, you should use np.concatenate你应该使用np.concatenate而不是加法
  • cols[18] is not an array -- it is an element of the array. cols[18]不是数组——它是数组的一个元素。 You cannot add a number and a array (if what you want to do is to append the element to the array)您不能添加数字和数组(如果您想做的是将元素附加到数组中)
cols2 = np.concatenate([cols[:17], cols[19:22], [cols[18]]])

or you can keep cols as a list (not converting it to numpy array and use list addition):或者您可以将 cols 保留为列表(不将其转换为numpy数组并使用列表添加):

cols = df.columns.tolist()
cols2 = cols[:17] + cols[19:22] + [cols[18]]

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')

暂无
暂无

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

相关问题 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 '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') 类型错误:ufunc &#39;add&#39; 不包含具有签名匹配类型的循环 - TypeError: ufunc 'add' did not contain a loop with signature matching types 类型错误: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') 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 &#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') 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;S23&#39;) dtype(&#39;S23&#39;) dtype(&#39;S23&#39;) 的循环 - TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('S23') dtype('S23') dtype('S23')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM