【发布时间】:2020-07-04 00:12:03
【问题描述】:
我是 Python 用户的初学者。 当我尝试在下面编写代码时发生错误
import numpy as np
np.array(['a', 'b', 'c']) + np.array(['d' ,'e', 'f'])
TypeError: ufunc 'add' did not contain a loop with signature matching types dtype('<U1') dtype('<U1') dtype('<U1')
所以我尝试设置dtype = '<U1',但没有成功
import numpy as np
np.array(['a', 'b', 'c'], dtype='<U1') + np.array(['d' ,'e', 'f'], dtype='<U1')
如何连接这些 np.arrays 而不会出错?
【问题讨论】:
-
你想连接数组方式(或)元素方式吗?
-
+用于字符串和列表的连接,但用于数组的数字加法。正如错误所说,它不是为字符数组定义的。