# 矩阵合并np.c\_和np.r\_

<https://blog.csdn.net/yj1556492839/article/details/79031693>

np.r\_是**按列**连接两个矩阵，就是把两矩阵上下相加，要求列数相等，类似于pandas中的concat()。 np.c\_是**按行**连接两个矩阵，就是把两矩阵左右相加，要求行数相等，类似于pandas中的merge()。

```python
import numpy as np
a = np.array([1, 2, 3])
b = np.array([4, 5, 6])
c = np.c_[a,b]

print(np.r_[a,b])
print(c)
print(np.c_[c,a])
#
[1 2 3 4 5 6]

[[1 4]
 [2 5]
 [3 6]]

[[1 4 1]
 [2 5 2]
 [3 6 3]]
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/numpy-pandas-matplotlib/numpy/xian-dai/he-bing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
