reshape(-1,1)
时间: 2023-08-29 17:12:44 浏览: 77
The function reshape(-1,1) is used in Python to reshape an array or a matrix into a new shape where the number of columns is fixed to 1, but the number of rows can be determined automatically based on the original shape of the matrix.
For example, consider the following matrix:
```
import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
```
The original shape of the matrix is (3,3), which means it has three rows and three columns. If we apply the reshape(-1,1) function to this matrix, it will create a new matrix with one column and nine rows, like this:
```
new_arr = arr.reshape(-1,1)
print(new_arr)
```
Output:
```
array([[1],
[2],
[3],
[4],
[5],
[6],
[7],
[8],
[9]])
```
Here, the reshape(-1,1) function has automatically determined that the new matrix should have nine rows (since the original matrix had nine elements) and one column (since we specified that the number of columns should be fixed to 1).
相关推荐
![](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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)