np.subtract
时间: 2023-12-16 07:05:01 浏览: 36
np.subtract 是 NumPy 库中的一个函数,用于计算两个数组的差,返回一个新的数组。具体用法可以参考以下示例:
```python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
c = np.subtract(a, b)
print(c) # 输出 [-1, -1, -1]
```
在上面的例子中,np.subtract 计算了数组 a 和 b 的差,并将结果保存在新的数组 c 中。
相关问题
np.subtract()
np.subtract() is a function in the NumPy library of Python that performs element-wise subtraction of two arrays or a scalar and an array. It returns a new array with the result of the subtraction. The syntax for np.subtract() is:
np.subtract(x1, x2, /, out=None, *, where=True, casting='same_kind', order='K', dtype=None, subok=True[, signature, extobj])
- x1: First input array
- x2: Second input array or scalar
- out: Optional output array
- where: Optional boolean array indicating where to perform the operation
- casting: Typecasting rules for the operation
- order: Order in which to process the array elements
- dtype: Data type for the output array
- subok: If True, the subclass of the output array is preserved.
np.subtract中三个变量
`np.subtract` 是 NumPy 库中的一个函数,用于计算两个数组的差值。
该函数有三个参数,分别是:
- `x1`:第一个数组。
- `x2`:第二个数组。
- `out`:可选参数,用于指定输出结果的数组。如果未指定,则会创建一个新的数组。
示例代码:
```python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.subtract(a, b)
print(c) # 输出 [-3 -3 -3]
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.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)
![](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)