关于hstack和Svstack
关于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]])
>>>
最新文章
- zookeeper_service 出错 ........... are only available on JDK 1.5 and higher
- Python基础:函数式编程
- 随机删除数据库N条记录
- hdu 1515 Anagrams by Stack
- 405 HTTP method GET is not supported by this URL
- 算法起步之Kruskal算法
- UML部署图和图九组件图
- 安装Windows2012操作系统 - 初学者系列 - 学习者系列文章
- Tomcat中定制阀门
- 002_Python多线程相当于单核多线程的论证
- MyBatis(八)联合查询 级联属性封装结果集
- UE4渲染笔记
- unity UI如何开启(显示)或者关闭(隐藏)Panel界面最好?
- 2018-计算机系机试-A
- Spring Boot 单元测试详解+实战教程
- MongoDB之 的Rollback讲解及避免
- Windows Server 2016 禁止自动更新后重启
- mysql中如何使用一句话将一个表的数据导入到另一个表中:insert into ...select
- ActiveMQ与Spring整合-MessageListener
- mysql查询某个库的表个数
热门文章
- tps吞吐量映射的问题
- C++入门经典-例6.12-使用数组地址将二维数组输出
- TCP层bind系统调用的实现分析
- linux下文件权限更改(转载)
- 在Linux上安装ipmitool
- [论文理解] Spatial Transformer Networks
- leetcode-easy-string- 8 String to Integer (atoi)
- Electron对JQuery的支持问题
- 阶段3 2.Spring_03.Spring的 IOC 和 DI_3 spring基于XML的IOC环境搭建和入门
- Eclipse_Package Presentation