Help us understand the problem. What is going on with this article?

# やりたいこと

numpy配列をappendしたい。

# 一次元

```array1 = np.array([])
array1 = np.append(array1, np.array([1, 2, 3]))
array1 = np.append(array1, np.array([4, 5, 6]))
array1
```
```array([1., 2., 3., 4., 5., 6.])
```

# 二次元

```array2 = np.empty((0,3))
array2 = np.append(array2, np.array([[1, 2, 3]]), axis = 0)
array2 = np.append(array2, np.array([[4, 5, 6]]), axis = 0)
array2
```
```array([[1., 2., 3.],
[4., 5., 6.]])
```

```array2 = np.empty((0,3))
array2 = np.append(array2, np.array([1, 2, 3]), axis = 0)
array2 = np.append(array2, np.array([4, 5, 6]), axis = 0)
array2
```
```---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-56-0cbe71e01df5> in <module>
1 array2 = np.empty((0,3))
----> 2 array2 = np.append(array2, np.array([1, 2, 3]), axis = 0)
3 array2 = np.append(array2, np.array([4, 5, 6]), axis = 0)
4 array2

~\Anaconda3\envs\tensorflow\lib\site-packages\numpy\lib\function_base.py in append(arr, values, axis)
4526         values = ravel(values)
4527         axis = arr.ndim-1
-> 4528     return concatenate((arr, values), axis=axis)

ValueError: all the input arrays must have same number of dimensions

```

つまり以下のである。

```array3 = np.array([1, 2, 3])
array4 = np.array([[1, 2, 3]])
array5 = np.empty((0,3))
print(array3.shape)
print(array4.shape)
print(array5.shape)
```
```(3,)
(1, 3)
(0, 3)
```

ちなみに

```np.array([array3]).shape
```
```(1, 3)
```

# 多次元

```import numpy as np
a = np.random.randn(1000, 10)
b = np.random.randn(1000, 10)
c = np.random.randn(1000, 10)
new_img = np.empty((0,1000,10))
new_img = np.append(new_img,np.array([a]),axis=0)
new_img = np.append(new_img,np.array([b]),axis=0)
new_img = np.append(new_img,np.array([c]),axis=0)
new_img.shape

```
```(3, 1000, 10)
```

# axisについて

```array2 = np.random.randn(1000,100,10,1)
print(array2.shape)
array2 = np.append(array2, array2, axis = 0)
array2 = np.append(array2, array2, axis = 0)
array2 = np.append(array2, array2, axis = 0)
print(array2.shape)
```
```(1000, 100, 10, 1)
(8000, 100, 10, 1)
```
```array2 = np.random.randn(1000,100,10,1)
print(array2.shape)
array2 = np.append(array2, array2, axis = 1)
array2 = np.append(array2, array2, axis = 1)
array2 = np.append(array2, array2, axis = 1)
print(array2.shape)
```
```(1000, 100, 10, 1)
(1000, 800, 10, 1)
```
```array2 = np.random.randn(1000,100,10,1)
print(array2.shape)
array2 = np.append(array2, array2, axis = 2)
array2 = np.append(array2, array2, axis = 2)
array2 = np.append(array2, array2, axis = 2)
print(array2.shape)
```
```(1000, 100, 10, 1)
(1000, 100, 80, 1)
```
```array2 = np.random.randn(1000,100,10,1)
print(array2.shape)
array2 = np.append(array2, array2, axis = 3)
array2 = np.append(array2, array2, axis = 3)
array2 = np.append(array2, array2, axis = 3)
print(array2.shape)
```
```(1000, 100, 10, 1)
(1000, 100, 10, 8)
```
Why do not you register as a user and use Qiita more conveniently?
1. We will deliver articles that match you
By following users and tags, you can catch up information on technical fields that you are interested in as a whole
2. you can read useful information later efficiently
By "stocking" the articles you like, you can search right away