a = np.array格式怎么相减
时间: 2023-11-23 17:17:20 浏览: 121
对Python 中矩阵或者数组相减的法则详解
To subtract two NumPy arrays element-wise, you can simply use the subtraction operator `-` between the two arrays. Here's an example:
```python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([2, 4, 6])
c = b - a
print(c)
```
Output:
```
[1 2 3]
```
In this example, we define two NumPy arrays `a` and `b` with the same length. Then, we subtract `a` from `b` using the `-` operator and store the result in a new NumPy array `c`. The resulting array `c` contains the element-wise difference between `b` and `a`, which is `[1, 2, 3]`.
Note that the two arrays `a` and `b` must have the same shape (i.e., the same number of elements) in order to be subtracted element-wise.
阅读全文