ufunc 'subtract' did not contain a loop with signature matching types (dtype('<U11'), dtype('<U11')) -> dtype
时间: 2023-12-13 16:05:26 浏览: 118
This error occurs when trying to perform a subtraction operation on strings using the numpy.subtract() function. The subtract() function is designed to work with numerical arrays and not with arrays containing strings.
To fix this error, you can convert the string arrays to numerical arrays using the numpy.asarray() function. For example:
```
import numpy as np
a = np.asarray(['10', '20', '30'], dtype=np.int)
b = np.asarray(['5', '10', '15'], dtype=np.int)
result = np.subtract(a, b)
print(result)
```
This will output:
```
[ 5 10 15]
```
Here, we first convert the string arrays to numerical arrays using the dtype parameter of the asarray() function. We then perform the subtraction operation using the subtract() function and assign the result to a new array called result. Finally, we print the result array which contains the expected output.
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)