# numpy - 将NumPy数组附加到NumPy数组

``````
>>> M = np.array([])
>>> M
array([], dtype=float64)
>>> M.append(a,axis=0)
Traceback (most recent call last):
File"<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'append'
>>> a
array([1, 2, 3])

``````

``````
In [1]: import numpy

In [2]: a = array([[1,2,3],[4,5,6]])

In [3]: b = array([[9,8,7],[6,5,4]])

In [4]: numpy.concatenate((a,b))
Out[4]:
array([[1, 2, 3],
[4, 5, 6],
[9, 8, 7],
[6, 5, 4]])

``````

``````
In [1]: a = array([1,2,3])

In [2]: b = array([4,5,6])

In [3]: numpy.vstack((a,b))
Out[3]:
array([[1, 2, 3],
[4, 5, 6]])

``````

``` ```
numpy.append(M, a)

``` ```

``````
In [2]: import numpy as np

In [3]: a = np.array([1,2,3])

In [4]: b = np.array([1.,2.,3.])

In [5]: c = np.array(['a','b','c'])

In [6]: np.append(a,b)
Out[6]: array([ 1., 2., 3., 1., 2., 3.])

In [7]: a.dtype
Out[7]: dtype('int64')

In [8]: np.append(a,c)
Out[8]:
array(['1', '2', '3', 'a', 'b', 'c'],
dtype='|S1')

``````

``````
a = [4.1, 6.21, 1.0]

``````

``````
def array_in_array(scalarlist):
return [(x,) for x in scalarlist]

``````

``````
In [72]: a = [4.1, 6.21, 1.0]

In [73]: a
Out[73]: [4.1, 6.21, 1.0]

In [74]: def array_in_array(scalarlist):
....: return [(x,) for x in scalarlist]
....:

In [75]: b = array_in_array(a)

In [76]: b
Out[76]: [(4.1,), (6.21,), (1.0,)]

``````