关于hstack和Svstack

import numpy as np
>>> a = np.array((1,2,3))
>>> a
array([1, 2, 3])
>>> b = np.array((2,3,4))
>>> np.hstack((a,b))
array([1, 2, 3, 2, 3, 4])
>>> np.vstack((a,b))
array([[1, 2, 3],
[2, 3, 4]])
>>> a = np.array([[1],[2],[3]])
>>> a
array([[1],
[2],
[3]])
>>> b = np.array([[2],[3],[4]])
>>> b
array([[2],
[3],
[4]])
>>> np.hstack((a,b))
array([[1, 2],
[2, 3],
[3, 4]])
>>> np.vstack((a,b))
array([[1],
[2],
[3],
[2],
[3],
[4]])

>>> cluster1 = np.random.uniform(0.5, 1.5, (2, 10))
>>> cluster1
array([[ 0.60849062, 0.80373879, 1.09272159, 1.17109014, 0.54168381,1.30649224, 0.82900102, 0.92583578, 0.79059036, 1.41629785],
[ 1.0175007 , 0.88072217, 0.54571384, 1.33015288, 1.27191768,0.57376194, 0.92339705, 0.97192802, 1.1190226 , 1.41452819]])
>>> cluster2 = np.random.uniform(3.5, 4.5, (2, 10))
>>> cluster2
array([[ 3.8001814 , 3.90072154, 4.02836533, 3.6499184 , 3.64592853,3.65085651, 3.75006055, 4.33185041, 3.70100798, 3.74613316],
[ 3.80366592, 3.80682426, 4.04532742, 4.3735719 , 4.38926895,3.78186945, 4.29025804, 3.66141714, 3.53704142, 3.83882232]])

#第一个数组和第二个数组在水平位置连接,2行*20列
>>> np.hstack((cluster1, cluster2)) #水平
array([[ 0.60849062, 0.80373879, 1.09272159, 1.17109014, 0.54168381,1.30649224, 0.82900102, 0.92583578, 0.79059036, 1.41629785,3.8001814 , 3.90072154, 4.02836533, 3.6499184 , 3.64592853,3.65085651, 3.75006055, 4.33185041, 3.70100798, 3.74613316],
[ 1.0175007 , 0.88072217, 0.54571384, 1.33015288, 1.27191768,0.57376194, 0.92339705, 0.97192802, 1.1190226 , 1.41452819,3.80366592, 3.80682426, 4.04532742, 4.3735719 , 4.38926895,3.78186945, 4.29025804, 3.66141714, 3.53704142, 3.83882232]])
>>> X = np.hstack((cluster1, cluster2)).T
#转置后20行*2列
>>> X
array([[ 0.60849062, 1.0175007 ],
[ 0.80373879, 0.88072217],
[ 1.09272159, 0.54571384],
[ 1.17109014, 1.33015288],
[ 0.54168381, 1.27191768],
[ 1.30649224, 0.57376194],
[ 0.82900102, 0.92339705],
[ 0.92583578, 0.97192802],
[ 0.79059036, 1.1190226 ],
[ 1.41629785, 1.41452819],
[ 3.8001814 , 3.80366592],
[ 3.90072154, 3.80682426],
[ 4.02836533, 4.04532742],
[ 3.6499184 , 4.3735719 ],
[ 3.64592853, 4.38926895],
[ 3.65085651, 3.78186945],
[ 3.75006055, 4.29025804],
[ 4.33185041, 3.66141714],
[ 3.70100798, 3.53704142],
[ 3.74613316, 3.83882232]])

>>> Y = np.vstack((cluster1, cluster2))   #垂直
>>> Y
array([[ 0.60849062, 0.80373879, 1.09272159, 1.17109014, 0.54168381,1.30649224, 0.82900102, 0.92583578, 0.79059036, 1.41629785],
         [ 1.0175007 , 0.88072217, 0.54571384, 1.33015288, 1.27191768,0.57376194, 0.92339705, 0.97192802, 1.1190226 , 1.41452819],
         [ 3.8001814 , 3.90072154, 4.02836533, 3.6499184 , 3.64592853,3.65085651, 3.75006055, 4.33185041, 3.70100798, 3.74613316],
         [ 3.80366592, 3.80682426, 4.04532742, 4.3735719 , 4.38926895,3.78186945, 4.29025804, 3.66141714, 3.53704142, 3.83882232]])

>>> Y=Y.T
>>> Y
array([[ 0.60849062, 1.0175007 , 3.8001814 , 3.80366592],
[ 0.80373879, 0.88072217, 3.90072154, 3.80682426],
[ 1.09272159, 0.54571384, 4.02836533, 4.04532742],
[ 1.17109014, 1.33015288, 3.6499184 , 4.3735719 ],
[ 0.54168381, 1.27191768, 3.64592853, 4.38926895],
[ 1.30649224, 0.57376194, 3.65085651, 3.78186945],
[ 0.82900102, 0.92339705, 3.75006055, 4.29025804],
[ 0.92583578, 0.97192802, 4.33185041, 3.66141714],
[ 0.79059036, 1.1190226 , 3.70100798, 3.53704142],
[ 1.41629785, 1.41452819, 3.74613316, 3.83882232]])
>>>

posted on 2016-03-10 17:05  qqhfeng16  阅读(645)  评论(0编辑  收藏  举报