reshape(-1,1)
时间: 2024-02-03 10:02:10 浏览: 88
The 'reshape(-1,1)' function is used in Python to change the shape of an array or matrix. The '-1' parameter represents an unknown dimension, while the '1' parameter represents the desired number of columns.
When applied to an array, the reshape function will convert it into a one-dimensional array with one column. For example, if we have an array with 12 elements, the reshape(-1,1) function will convert it into a 12x1 matrix.
Here's an example:
```
import numpy as np
arr = np.array([[1,2,3], [4,5,6], [7,8,9]])
new_arr = arr.reshape(-1,1)
print(arr)
print(new_arr)
```
Output:
```
[[1 2 3]
[4 5 6]
[7 8 9]]
[[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]]
```
In this example, we have an array with three rows and three columns. After applying the reshape(-1,1) function, we get a new array with nine rows and one column.