import numpy as np

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

a.shape
Out[3]: (2, 2)

b = np.array([[5, 6]])

b.shape
Out[5]: (1, 2)

np.concatenate((a, b))
Out[6]: 
array([[1, 2],
       [3, 4],
       [5, 6]])

c= np.concatenate((a, b))

c.shape
Out[8]: (3, 2)

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

d.shape
Out[10]: (3, 2)

e = np.concatenate((a, b), axis=1)
Traceback (most recent call last):

  File "<ipython-input-11-05a280a2cb02>", line 1, in <module>
    e = np.concatenate((a, b), axis=1)

ValueError: all the input array dimensions except for the concatenation axis must match exactly


e = np.concatenate((a, b.T), axis=1)

e.shape
Out[13]: (2, 3)

import numpy as np

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

a.shape
Out[3]: (2, 2)

b = np.array([[5, 6]])

b.shape
Out[5]: (1, 2)

np.concatenate((a, b))
Out[6]:
array([[1, 2],
[3, 4],
[5, 6]])

c= np.concatenate((a, b))

c.shape
Out[8]: (3, 2)

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

d.shape
Out[10]: (3, 2)

e = np.concatenate((a, b), axis=1)
Traceback (most recent call last):

File "<ipython-input-11-05a280a2cb02>", line 1, in <module>
e = np.concatenate((a, b), axis=1)

ValueError: all the input array dimensions except for the concatenation axis must match exactly


e = np.concatenate((a, b.T), axis=1)

e.shape
Out[13]: (2, 3)

e
Out[14]:
array([[1, 2, 5],
[3, 4, 6]])

posted on 2016-08-11 23:00  qqhfeng16  阅读(11334)  评论(0编辑  收藏  举报