Sparse Matrix's Transpose

原创 2016年05月31日 15:00:23

Sparse Matrix

Usually, suppose that there is m rows and n cols, and t non-zero element in a matrix. Make δ=t/(mn), δ is called sparse factor. If δ0.05, we could call the matrix a sparse matrix.

Transpose Algorithm

  • The data is ordered by row.

About classical method:

  • According to matrix’s diagonal, making half of number of all element( munu) tranpose is a easy way to realize matrix’s transpose.

    Time Complexity: O(munu)


There are two methods.
  • First

    Requirement:
    The result must orderly by col. If don’t require the result is orderly, We could do this in time O(nu).

    Description:
    From first row, find the elem whose row-num(i) is this row, and transpose to col.

    // M is source Matrix, T is target Matrix
    // mu is row-num, nu is col-num, tu is non-zero-num
    // .i is row, .j is col, .e is elem
    
    Status TranposeMatrix(Matrix M, Matrix &T) {
        T.mu = M.nu, T.nu = m.Mu, T.tu = M.tu;
        if (T.mu) {
            q = 1;
            for(col = 1; col <= M.nu; ++col)
            for(p = 1; p <= M.tu; ++p) 
                if(M.data[p].j == col) {
                    T.data[q].i = M.data[p].i;
                    T.data[q].j = M.data[p].j;
                    T.data[q].e = M.data[p].e;
                    ++q;
                }
        }
        return OK;
    }

    Obviously, there is nutu times operation.

    Time Complexity: O(nutu)

    If tumu, this method is bad.

  • second

    Name: Fast Transpose

    Description:
    If we could determine every col of result serial number, we could make every data right location.

    Known:
    cpot[1] = 1;
    cpot[col] = cpot[col- 1] + num[col- 1];

    Because the source data is ordered by row, we could make every col a point to mark this col’s the data sequence.

    Status FastTransposeMatrix(Matrix M, Matrix &T) {
        T.mu = M.nu; T.nu = M.mu; T.tu = M.tu;
        if(T.tu) {
            for(col = 1; col <= M.nu; ++col) num[col] = 0;
            for(t = 1; t <= M.tu; ++t) ++num[M.data[t].j];
            cpot[i] = 1;
    
            for (col = 2; col <= M.nu; ++col) cpot[col] = cpot[col - 1] + num [col - 1];
            for (p= 1; p<= M.tu; ++p) {
                col = M.data[p].j;
                q = cpot[col];
                T.data[q].i = M.data[p].j;
                T.data[q].j = M.data[p].i;
                T.data[q].e = M.data[p].e;
                ++ cpot[col];
            }
        }
    }

    Obviously, there is nu+tu times operation.

    Time Complexity: O(nu+tu)

    In worst situation, tu=munu, this time is O(munu), it still works well.

版权声明:如果文中有任何问题或者值得讨论的地方,都可以在下方留言或者QQ526664687,欢迎交流!!!

matrix transpose

  • 2014年08月11日 20:15
  • 380B
  • 下载

tensorflow中的不懂得知识点——转置函数 transpose

目前,对于tensorflow处于学习阶段,将不会的知识点进行罗列,以后明白了解了在对其进行补充。 1、转置函数 transpose 该函数包含两点: (1) 在tensorflow的教学网站...

python 矩阵转置transpose--实战应用详解

在读图片时,会用到这么的一段代码: image_vector_len = np.prod(image_size)#总元素大小,3*55*47 img = Image.open(path) ...

OpenCV代码提取:transpose函数的实现

OpenCV代码提取:transpose函数的实现

Uva 10895 - Matrix Transpose

这个就是说有这么一个矩阵,好多0,让你求转制 sort预处理 之后想辙输出就好 第一遍遍历的点,发现各种特殊状况不好弄 AC的是枚举第几行 #include #include #includ...
  • ronnoc
  • ronnoc
  • 2013年04月09日 22:47
  • 429

Inverse transpose matrix

对normal进行变换不能直接乘以变换矩阵,必须乘以inverse transpose matrix 给定一个顶点的Normal n,以及过该点的切平面上的一个向量u,且有变换矩阵T。u,n是行向量...
  • seizeF
  • seizeF
  • 2011年08月21日 18:16
  • 2565

transpose and pivot data in hive

1. 键-值对的形式存储数据有时候,我们在hive中编写hql的时候,可以用键-值对的形式存储结果。比如有一些同学在一些课程中的学习行为,我们可以记录成如下形式: student clas...

Fortran几个函数(DOT_PRODUCT+MATMUL+TRANSPOSE+RESHAPE)

DOT_PRODUCT函数(点积)     DOT_PRODUCT(VECTOR_A, VECTOR_B) computes the dot product multiplication...

sum,transpose 和 diag

和,转置和特征值 你可能已经发觉,一个魔方的相加它的元素的各种多种方式特的殊性质。如果你要相加单独任意行或列,或单独或两个主要对角线,你将总会得...

利用tf.nn.conv2d_transpose实现图片分辨率按指定倍数扩展

我有输入尺寸为 64x64x3 的图片,即高64, 宽64, 通道数3 我想通过transposed convolution 来使图片的高宽放大到2倍,即 128x128import tensorf...
  • wm6274
  • wm6274
  • 2017年06月16日 11:26
  • 152
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:Sparse Matrix's Transpose
举报原因:
原因补充:

(最多只允许输入30个字)