• 关于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]])
    >>>

  • 相关阅读:
    appium-flutter-driver 测试flutter_boost项目_Java语言
    appium-flutter-driver 测试flutter项目
    Android Studio 制作出来的9图无法进行拖拉,导致无法制作出正确的9图
    Flutter 正确删除emoji表情/正确分割字符串
    如何清除git仓库的所有提交记录,成为一个新的干净仓库
    js中this的总结
    python判断时间是否在某个时间段里面的三种方式
    centos7使用rpm包安装mysql5.74
    django学习之 从服务端上传文档与下载文档接口
    python 之阿里云短信服务接入流程短信接口
  • 原文地址:https://www.cnblogs.com/qqhfeng/p/5262616.html
Copyright © 2020-2023  润新知