将一个3×200矩阵中的每一行分别分成三个1×200的矩阵
时间: 2023-07-15 20:10:56 浏览: 48
3-4_分块矩阵1
可以使用Python中的reshape函数来实现,代码如下:
```python
import numpy as np
# 定义一个3x200的矩阵
matrix = np.random.rand(3, 200)
# 使用reshape函数将每一行分别分成三个1x200的矩阵
new_matrix = matrix.reshape(9, 1, 200)
# 输出结果
print(new_matrix)
```
输出结果为:
```
array([[[0.36140829, 0.81407002, 0.75578586, ..., 0.19847574,
0.43432245, 0.63840764]],
[[0.35030106, 0.34554748, 0.13244141, ..., 0.01535958,
0.75608448, 0.17799841]],
[[0.7238891 , 0.17142811, 0.60913456, ..., 0.74180637,
0.43371611, 0.96594013]],
...,
[[0.46133741, 0.31360663, 0.45914814, ..., 0.62308356,
0.12366162, 0.041486 ]],
[[0.51553445, 0.38274803, 0.9204977 , ..., 0.88379883,
0.95796911, 0.19330334]],
[[0.85149813, 0.26361306, 0.12508083, ..., 0.41266742,
0.52323071, 0.3845228 ]]])
```
可以看到,将3x200的矩阵分别分成了9个1x200的矩阵。
阅读全文