jupyter notebook多维数组运算
时间: 2024-01-26 20:04:08 浏览: 94
多维数组的运算
在Jupyter Notebook中,可以使用NumPy库进行多维数组运算。以下是一些常见的多维数组运算示例:
1. 数组加法:
```python
import numpy as np
arr = np.array([[1,2,3,2,1,4], [5,6,1,2,3,1]])
result = arr + 1
print(result)
```
输出:
```
[[2 3 4 3 2 5]
[6 7 2 3 4 2]]
```
2. 数组除法:
```python
import numpy as np
arr = np.array([[1,2,3,2,1,4], [5,6,1,2,3,1]])
result = arr / 2
print(result)
```
输出:
```
[[0.5 1. 1.5 1. 0.5 2. ]
[2.5 3. 0.5 1. 1.5 0.5]]
```
3. 数组与数组的运算:
```python
import numpy as np
arr1 = np.array([[1,2,3], [4,5,6]])
arr2 = np.array([[2,3,4], [5,6,7]])
result = arr1 + arr2
print(result)
```
输出:
```
[[ 3 5 7]
[ 9 11 13]]
```
这些示例展示了在Jupyter Notebook中使用NumPy库进行多维数组运算的基本操作。
阅读全文