column_stack
时间: 2023-10-02 14:08:42 浏览: 43
The `column_stack` function in NumPy is used to stack 1-D arrays as columns into a 2-D array. It takes a sequence of 1-D arrays and returns a 2-D array. If the input arrays have different shapes, they will be broadcasted to a common shape before stacking.
Syntax:
```python
numpy.column_stack(tup)
```
Parameters:
- `tup`: A sequence of 1-D arrays.
Return Value:
- A 2-D array formed by stacking the input arrays as columns.
Example:
```python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.array([7, 8, 9])
result = np.column_stack((a, b, c))
print(result)
```
Output:
```
array([[1, 4, 7],
[2, 5, 8],
[3, 6, 9]])
```
In the above example, three 1-D arrays `a`, `b`, and `c` are stacked column-wise using the `column_stack` function to form a 2-D array `result`.