Python Numpy 学习笔记(2)

来源:互联网 发布:wine mac 中文 编辑:程序博客网 时间:2024/06/06 23:17

今天主要说的是关于合并拆分的几个操作。

组合

水平组合,垂直组合,深度组合。

水平组合:

1.hstack (a,b)

2.concatenate ((a,b),axis=1)

from numpy import *a = array(arange(1, 10).reshape(3, 3))b = array(arange(11, 20).reshape(3, 3))c = hstack((a, b))d = concatenate((b, c), axis=1)print cprint d


垂直组合:

1.vstack((a,b))

2.concatenate ((a,b),axis=1)

from numpy import *a = array(arange(1, 10).reshape(3, 3))b = array(arange(11, 20).reshape(3, 3))c = vstack((a, b))d = concatenate((b, c), axis=0)print cprint d


深度组合:

1.dstack((a,b))

from numpy import *a = array(arange(1, 10).reshape(3, 3))b = array(arange(11, 20).reshape(3, 3))c = dstack((a, b))print c

数组的分割

水平分割

hsplit(a,x)

split(a,x,axis=1)

from numpy import *a = array(arange(1, 10).reshape(3, 3))b = hsplit(a, 3)c = split(a, 3, axis=1)print bprint c

垂直分割

vsplit(a,x)

split(a,x,axis=0)

from numpy import *a = array(arange(1, 10).reshape(3, 3))b = vsplit(a, 3)c = split(a, 3, axis=0)print bprint c
 

深度分割

dsplit(a,x)

from numpy import *a = array(arange(1, 28).reshape(3, 3, 3))b = dsplit(a, 3)print b




原创粉丝点击