numpy.concatenate

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]])

上一篇:POI导入导出Excel(HSSF格式,User Model方式)


下一篇:BizTalk开发系列(十五) Schema设计之Qualified 与Unqualified