np.stack axis=1
时间: 2023-09-09 21:10:18 浏览: 106
`np.stack` is a function in NumPy that is used to join a sequence of arrays along a new axis. The `axis` parameter specifies the axis along which the arrays will be stacked. When `axis=1`, it means that the arrays will be stacked horizontally, i.e., column-wise.
Here's an example:
```python
import numpy as np
arr1 = np.array([1, 2, 3])
arr2 = np.array([4, 5, 6])
arr3 = np.array([7, 8, 9])
stacked_arr = np.stack((arr1, arr2, arr3), axis=1)
print(stacked_arr)
```
Output:
```
array([[1, 4, 7],
[2, 5, 8],
[3, 6, 9]])
```
In this example, we have three arrays `arr1`, `arr2`, and `arr3`. We use `np.stack` to stack them horizontally (along `axis=1`) to get a new array `stacked_arr`. The resulting array has three rows and three columns, where each column represents an array.
阅读全文