zoukankan      html  css  js  c++  java
  • 稀疏矩阵合并 归一化

     np.hstack((X, X2))
    array([ <49998x70000 sparse matrix of type '<class 'numpy.float64'>'
            with 1135520 stored elements in Compressed Sparse Row format>,
            <49998x70000 sparse matrix of type '<class 'numpy.int64'>'
            with 1135520 stored elements in Compressed Sparse Row format>], 
           dtype=object)

        <49998x1400000 sparse matrix of type '<class 'numpy.float64'>'
         with 2271040 stored elements in Compressed Sparse Row format>
    from scipy.sparse import hstack
    hstack((X, X2))
    

    Using the numpy.hstack will create an array with two sparse matrix objects.

    scipy.sparse.bmat

    from scipy.sparse import coo_matrix, bmat
    >>> A = coo_matrix([[1, 2], [3, 4]])
    >>> B = coo_matrix([[5], [6]])
    >>> C = coo_matrix([[7]])
    >>> bmat([[A, B], [None, C]]).toarray()
    array([[1, 2, 5],
           [3, 4, 6],
           [0, 0, 7]])
    >>>
    >>> bmat([[A, None], [None, C]]).toarray()
    array([[1, 2, 0],
           [3, 4, 0],
           [0, 0, 7]])

    归一化

    >>> X = [[ 1., -1.,  2.],
    ...      [ 2.,  0.,  0.],
    ...      [ 0.,  1., -1.]]
    >>> X_normalized = preprocessing.normalize(X, norm='l2')
    
    >>> X_normalized                                      
    array([[ 0.40..., -0.40...,  0.81...],
           [ 1.  ...,  0.  ...,  0.  ...],
           [ 0.  ...,  0.70..., -0.70...]])

    norm : ‘l1’, ‘l2’, or ‘max’, optional (‘l2’ by default)

    The norm to use to normalize each non zero sample (or each non-zero feature if axis is 0).

    参考:
    http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.normalize.html#sklearn.preprocessing.normalize
    https://www.baidu.com/link?url=epjyVGjvTldY3YcjfaWPamA76GuWxnf3ZOH0FAeWHiKqp60g6_dyzM95CAyj30j-IX2YRD0o9zdgTO-nVzqFjEb3GX_Q2leL_uS1_1qCyINyv8rxh0h0lW8aLrINECNW&wd=&eqid=83485e4f0000bc06000000035822acd4
  • 相关阅读:
    二、编写输出“Hello World”
    实验一:JDK下载与安装、Eclipse下载与使用总结心得
    C++引用
    数组类型与sizeof与指针的引用
    电源已接通,未充电
    改变Web Browser控件IE版本
    “stdafx.h”: No such file or directory
    word2013 blog test
    Editplus配置VC++(1) 及相关注意事项
    VC++6.0在Win7以上系统上Open或Add to Project files崩溃问题 解决新办法
  • 原文地址:https://www.cnblogs.com/zle1992/p/6046547.html
Copyright © 2011-2022 走看看