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
  • 相关阅读:
    VS2015使用scanf报错解决方案
    C++的标准模板库(STL)简介
    C++中常用特殊符号简介(& , * , : , :: , ->)
    C++中#include <xxx.h>和#include "xxx.h"的区别(尖括号和双引号的区别)
    C++中#include的工作原理
    opencv中Mat与IplImage,CVMat类型之间转换
    C++数据类型简析
    让你在DOS中任意切换目录
    七种Prolog解释器/编译器
    C++中引用(&)的用法和应用实例
  • 原文地址:https://www.cnblogs.com/zle1992/p/6046547.html
Copyright © 2011-2022 走看看