# insert()append()delete()concatenate()hstack()vstack()等操作

<https://blog.csdn.net/weixin_37895339/article/details/78442555>

操作**不改变原数据，需要等式赋值**

## numpy.insert(arr,obj,value,axis=None)

value为插入的数值 arr:为目标向量 obj:为目标位置 value:为想要插入的数值 axis:为插入的维度

```python
#对a中,0维度,目标位1处，插入:[1,1,1,1]
a=np.insert(a,1,[1,1,1,1],0)
# a
array([[ 0,  1,  2,  3],
       [ 1,  1,  1,  1],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11]])
```

## numpy.append(arr,values,axis=None)

与insert类似，只是append只是将values插入到目标arr的最后。 这里values跟arr应该为相同维度的向量。

## numpy.delete(arr,obj,axis=None)

arr:输入向量 obj:表明哪一个子向量应该被移除。可以为整数或一个int型的向量 axis:表明删除哪个轴的子向量，若默认，则返回一个被拉平的向量

## np.concatenate((a,b),axis=0)

```python
import numpy as np

a = np.array(np.arange(12).reshape(3, 4))
b = np.array(np.arange(12, 24).reshape(3, 4))

print(a)
print(b)
c=np.concatenate((a,b),axis=0)
print()
print(c)
'''
a: [[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]]
b: [[12 13 14 15]
 [16 17 18 19]
 [20 21 22 23]]
c: [[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]
 [12 13 14 15]
 [16 17 18 19]
 [20 21 22 23]]
'''
```

## hstack()水平堆叠

```python
a=[1,2,3] b=[4,5,6] 
print(np.hstack((a,b))) 
输出：[1 2 3 4 5 6 ]
```

## vstack()垂直堆叠

```python
a=[1,2,3]
b=[4,5,6]
print(np.vstack((a,b)))

输出：
[[1 2 3]
 [4 5 6]]
```


---

# 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/insert-append-delete-concatenate-hstack-vstack.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.
