码迷,mamicode.com
首页 > 其他好文 > 详细

numpy.concatenate

时间:2016-08-12 01:03:46      阅读:213      评论:0      收藏:0      [点我收藏+]

标签:

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

numpy.concatenate

标签:

原文地址:http://www.cnblogs.com/qqhfeng/p/5763120.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!