• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python sppy.csarray函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中sppy.csarray函数的典型用法代码示例。如果您正苦于以下问题:Python csarray函数的具体用法?Python csarray怎么用?Python csarray使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了csarray函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: testStr

    def testStr(self):
        nrow = 5
        ncol = 7

        storagetypes = ["col", "row"]

        for storagetype in storagetypes:
            A = csarray((nrow, ncol), storagetype=storagetype)
            A[0, 1] = 1
            A[1, 3] = 5.2
            A[3, 3] = -0.2

            outputStr = "csarray dtype:float64 shape:(5, 7) non-zeros:3 storage:" + A.storagetype + "\n"
            outputStr += "(0, 1) 1.0\n"
            outputStr += "(1, 3) 5.2\n"
            outputStr += "(3, 3) -0.2"
            self.assertEquals(str(A), outputStr)

            B = csarray((5, 5), storagetype=storagetype)
            outputStr = "csarray dtype:float64 shape:(5, 5) non-zeros:0 storage:" + B.storagetype + "\n"
            self.assertEquals(str(B), outputStr)

            outputStr = "csarray dtype:float64 shape:(10,) non-zeros:3\n"
            outputStr += "(0) 23.0\n"
            outputStr += "(3) 1.2\n"
            outputStr += "(4) -8.0"
            self.assertEquals(str(self.a), outputStr)

            outputStr = "csarray dtype:float64 shape:(3,) non-zeros:0\n"
            self.assertEquals(str(self.c), outputStr)
开发者ID:tguttenb,项目名称:MoMs-for-StochasticLanguages,代码行数:30,代码来源:csarrayTest.py


示例2: testSub

    def testSub(self):
        nptst.assert_array_equal((self.A - self.A).toarray(), self.A.toarray() * 0)
        nptst.assert_array_equal((self.B - self.B).toarray(), self.B.toarray() * 0)
        nptst.assert_array_equal((self.C - self.C).toarray(), self.C.toarray() * 0)
        nptst.assert_array_equal((self.D - self.D).toarray(), self.D.toarray() * 0)
        nptst.assert_array_equal((self.F - self.F).toarray(), self.F.toarray() * 0)
        nptst.assert_array_equal((self.G - self.G).toarray(), self.G.toarray() * 0)
        nptst.assert_array_equal((self.H - self.H).toarray(), self.H.toarray() * 0)

        nptst.assert_array_equal((self.B * 2 - self.B).toarray(), self.B.toarray())

        A = csarray((5, 5))
        A[0, 1] = 4
        A[1, 3] = 2
        A[3, 3] = 1

        B = csarray((5, 5))
        B[0, 2] = 9.2
        B[2, 3] = -5
        B[3, 4] = 12

        nptst.assert_array_equal((A - B).toarray(), A.toarray() - B.toarray())

        nptst.assert_array_equal((self.a - self.a).toarray(), self.a.toarray() * 0)
        nptst.assert_array_equal((self.b - self.b).toarray(), self.b.toarray() * 0)
        nptst.assert_array_equal((self.c - self.c).toarray(), self.c.toarray() * 0)
开发者ID:tguttenb,项目名称:MoMs-for-StochasticLanguages,代码行数:26,代码来源:csarrayTest.py


示例3: testAdd

    def testAdd(self):
        # print(self.A.__add__(self.A._array))
        nptst.assert_array_equal((self.A + self.A).toarray(), self.A.toarray() * 2)
        nptst.assert_array_equal((self.B + self.B).toarray(), self.B.toarray() * 2)
        nptst.assert_array_equal((self.C + self.C).toarray(), self.C.toarray() * 2)
        nptst.assert_array_equal((self.D + self.D).toarray(), self.D.toarray() * 2)

        nptst.assert_array_equal((self.F + self.F).toarray(), self.F.toarray() * 2)
        nptst.assert_array_equal((self.G + self.G).toarray(), self.G.toarray() * 2)
        nptst.assert_array_equal((self.H + self.H).toarray(), self.H.toarray() * 2)

        A = csarray((5, 5))
        A[0, 1] = 4
        A[1, 3] = 2
        A[3, 3] = 1

        B = csarray((5, 5))
        B[0, 2] = 9.2
        B[2, 3] = -5
        B[3, 4] = 12

        nptst.assert_array_equal((A + B).toarray(), A.toarray() + B.toarray())

        nptst.assert_array_equal((self.a + self.a).toarray(), self.a.toarray() * 2)
        nptst.assert_array_equal((self.b + self.b).toarray(), self.b.toarray() * 2)
        nptst.assert_array_equal((self.c + self.c).toarray(), self.c.toarray() * 2)
开发者ID:tguttenb,项目名称:MoMs-for-StochasticLanguages,代码行数:26,代码来源:csarrayTest.py


示例4: testHadamard

    def testHadamard(self):
        nptst.assert_array_equal((self.A.hadamard(self.A)).toarray(), (self.A.toarray()) ** 2)
        nptst.assert_array_equal((self.B.hadamard(self.B)).toarray(), self.B.toarray() ** 2)
        nptst.assert_array_equal((self.C.hadamard(self.C)).toarray(), self.C.toarray() ** 2)
        nptst.assert_array_equal((self.D.hadamard(self.D)).toarray(), self.D.toarray() ** 2)

        nptst.assert_array_equal((self.F.hadamard(self.F)).toarray(), self.F.toarray() ** 2)
        nptst.assert_array_equal((self.G.hadamard(self.G)).toarray(), self.G.toarray() ** 2)
        nptst.assert_array_equal((self.H.hadamard(self.H)).toarray(), self.H.toarray() ** 2)

        for storagetype in self.storagetypes:
            A = csarray((5, 5), storagetype=storagetype)
            A[0, 1] = 4
            A[2, 3] = -1.2
            A[1, 3] = 2
            A[3, 3] = 1

            B = csarray((5, 5), storagetype=storagetype)
            B[0, 2] = 9.2
            B[2, 3] = -5
            B[3, 4] = 12
            B[3, 3] = 12

            C = csarray((5, 5), storagetype=storagetype)

            nptst.assert_array_equal((A.hadamard(B)).toarray(), A.toarray() * B.toarray())
            nptst.assert_array_equal((A.hadamard(C)).toarray(), C.toarray())

        nptst.assert_array_equal((self.a.hadamard(self.a)).toarray(), (self.a.toarray()) ** 2)
        nptst.assert_array_equal((self.b.hadamard(self.b)).toarray(), (self.b.toarray()) ** 2)
        nptst.assert_array_equal((self.c.hadamard(self.c)).toarray(), (self.c.toarray()) ** 2)
开发者ID:tguttenb,项目名称:MoMs-for-StochasticLanguages,代码行数:31,代码来源:csarrayTest.py


示例5: testHadamard

 def testHadamard(self): 
    nptst.assert_array_equal((self.A.hadamard(self.A)).toarray(), (self.A.toarray())**2)
    nptst.assert_array_equal((self.B.hadamard(self.B)).toarray(), self.B.toarray()**2)
    nptst.assert_array_equal((self.C.hadamard(self.C)).toarray(), self.C.toarray()**2)
    nptst.assert_array_equal((self.D.hadamard(self.D)).toarray(), self.D.toarray()**2)
    
    nptst.assert_array_equal((self.F.hadamard(self.F)).toarray(), self.F.toarray()**2)
    
    A = csarray((5, 5))
    A[0, 1] = 4
    A[2, 3] = -1.2
    A[1, 3] = 2
    A[3, 3] = 1
    
    B = csarray((5, 5))
    B[0, 2] = 9.2
    B[2, 3] = -5
    B[3, 4] = 12
    B[3, 3] = 12
    
    C = csarray((5, 5))
    
    nptst.assert_array_equal((A.hadamard(B)).toarray(), A.toarray()*B.toarray())
    nptst.assert_array_equal((A.hadamard(C)).toarray(), C.toarray())
    
    nptst.assert_array_equal((self.a.hadamard(self.a)).toarray(), (self.a.toarray())**2)
    nptst.assert_array_equal((self.b.hadamard(self.b)).toarray(), (self.b.toarray())**2)
    nptst.assert_array_equal((self.c.hadamard(self.c)).toarray(), (self.c.toarray())**2)
开发者ID:ElectronicRU,项目名称:sppy,代码行数:28,代码来源:csarrayTest.py


示例6: testDot

 def testDot(self): 
    A = csarray((5, 5))
    A[0, 1] = 4
    A[2, 3] = -1.2
    A[1, 3] = 2
    A[3, 3] = 1 
    
    B = A.dot(A)
    nptst.assert_array_equal(B.toarray(), A.toarray().dot(A.toarray()))
    
    B = self.D.dot(self.D)
    nptst.assert_array_equal(B.toarray(), self.D.toarray().dot(self.D.toarray()))
    
    C = csarray((5, 2))
    for i in range(5): 
        for j in range(2): 
            C[i, j] = 1
            
    self.assertRaises(ValueError, C.dot, C)
    B = A.dot(C)
    nptst.assert_array_equal(B.toarray(), A.toarray().dot(C.toarray()))        
    
    self.assertEquals((self.a.dot(self.a)), (self.a.dot(self.a)))
    self.assertEquals((self.b.dot(self.b)), (self.b.dot(self.b)))
    self.assertEquals((self.c.dot(self.c)), (self.c.dot(self.c)))
开发者ID:ElectronicRU,项目名称:sppy,代码行数:25,代码来源:csarrayTest.py


示例7: testStr

 def testStr(self): 
     nrow = 5 
     ncol = 7
     A = csarray((nrow, ncol))
     A[0, 1] = 1
     A[1, 3] = 5.2
     A[3, 3] = -0.2
     
     outputStr = "csarray dtype:float64 shape:(5, 7) non-zeros:3\n" 
     outputStr += "(0, 1) 1.0\n"
     outputStr += "(1, 3) 5.2\n"
     outputStr += "(3, 3) -0.2"
     self.assertEquals(str(A), outputStr) 
     
     B = csarray((5, 5))
     outputStr = "csarray dtype:float64 shape:(5, 5) non-zeros:0\n" 
     self.assertEquals(str(B), outputStr) 
     
     outputStr = "csarray dtype:float64 shape:(10,) non-zeros:3\n"
     outputStr +="(0) 23.0\n"
     outputStr +="(3) 1.2\n"
     outputStr +="(4) -8.0"
     self.assertEquals(str(self.a), outputStr) 
     
     outputStr = "csarray dtype:float64 shape:(3,) non-zeros:0\n" 
     self.assertEquals(str(self.c), outputStr) 
开发者ID:ElectronicRU,项目名称:sppy,代码行数:26,代码来源:csarrayTest.py


示例8: testGetOmegaListPtr

    def testGetOmegaListPtr(self): 
        import sppy 
        m = 10 
        n = 5
        X = scipy.sparse.rand(m, n, 0.1)
        X = X.tocsr()
        
        indPtr, colInds = SparseUtils.getOmegaListPtr(X)

        for i in range(m): 
            omegai = colInds[indPtr[i]:indPtr[i+1]]
            nptst.assert_array_almost_equal(omegai, X.toarray()[i, :].nonzero()[0])
        
        Xsppy = sppy.csarray(X)
        indPtr, colInds  = SparseUtils.getOmegaListPtr(Xsppy)
        
        for i in range(m):
            omegai = colInds[indPtr[i]:indPtr[i+1]]
            nptst.assert_array_almost_equal(omegai, X.toarray()[i, :].nonzero()[0])
        
        #Test a zero array (scipy doesn't work in this case)
        X = sppy.csarray((m,n))
        
        indPtr, colInds = SparseUtils.getOmegaListPtr(X)
   
        for i in range(m): 
            omegai = colInds[indPtr[i]:indPtr[i+1]]
开发者ID:charanpald,项目名称:sandbox,代码行数:27,代码来源:SparseUtilsTest.py


示例9: testBiCGSTAB

 def testBiCGSTAB(self): 
     #This doesn't always converge 
     numRuns = 10 
     
     for i in range(numRuns): 
         n = numpy.random.randint(5, 20)
         A = numpy.random.rand(n, n)
         x = numpy.random.rand(n)
         
         b = A.dot(x)
         
         A = sppy.csarray(A)
         
         x2, output = sppy.linalg.biCGSTAB(A, b, tol=10**-6, maxIter=n)
         
         if output == 0: 
             nptst.assert_array_almost_equal(x, x2, 3)
             
     #Try with bad input 
     m = 3
     n = 5
     A = numpy.random.rand(n, m)
     A = sppy.csarray(A)
     x = numpy.random.rand(m)
     b = A.dot(x)
     
     self.assertRaises(ValueError, sppy.linalg.biCGSTAB, A, b)
     
     A = numpy.random.rand(n, n)
     A = sppy.csarray(A)
     b = numpy.array(n+1)
     self.assertRaises(ValueError, sppy.linalg.biCGSTAB, A, b)
开发者ID:ICML14MoMCompare,项目名称:spectral-learn,代码行数:32,代码来源:coreTest.py


示例10: testNDim

 def testNDim(self): 
     A = csarray((5, 7))
     self.assertEquals(A.ndim, 2)
     
     A = csarray((0, 0))
     self.assertEquals(A.ndim, 2)
     
     self.assertEquals(self.a.ndim, 1)
     self.assertEquals(self.b.ndim, 1)
开发者ID:phaustin,项目名称:sppy,代码行数:9,代码来源:csarrayTest.py


示例11: loadMatrix

 def loadMatrix(filename):
     M = scipy.io.mmread(filename)
     if type(M) == numpy.ndarray:
         M2 = sppy.csarray(M)
     elif scipy.sparse.issparse(M):
         M2 = sppy.csarray(M.shape, dtype=M.dtype)
         M2[M.nonzero()] = M.data 
             
     return M2 
开发者ID:awj223,项目名称:Insight-Data-Engineering-Code-Challenge,代码行数:9,代码来源:CsArrayGraph.py


示例12: testNonZeroInds

 def testNonZeroInds(self): 
     
     (rowInds, colInds) = self.B.nonzero()
     
     for i in range(rowInds.shape[0]): 
         self.assertNotEqual(self.B[rowInds[i], colInds[i]], 0)
     
     self.assertEquals(self.B.getnnz(), rowInds.shape[0])
     self.assertEquals(self.B.sum(), self.B[rowInds, colInds].sum())
     
     (rowInds, colInds) = self.C.nonzero()
     
     for i in range(rowInds.shape[0]): 
         self.assertNotEqual(self.C[rowInds[i], colInds[i]], 0)   
         
     self.assertEquals(self.C.getnnz(), rowInds.shape[0])
     self.assertEquals(self.C.sum(), self.C[rowInds, colInds].sum())
     
     (rowInds, colInds) = self.F.nonzero()
     
     for i in range(rowInds.shape[0]): 
         self.assertNotEqual(self.F[rowInds[i], colInds[i]], 0)   
         
     self.assertEquals(self.F.getnnz(), rowInds.shape[0])
     self.assertEquals(self.F.sum(), self.F[rowInds, colInds].sum())
     
     (inds, ) = self.a.nonzero()
     for i in range(inds.shape[0]): 
         self.assertNotEqual(self.a[inds[i]], 0)  
     
     #Try an array with no non zeros 
     nrow = 5 
     ncol = 7
     A = csarray((nrow, ncol))
     (rowInds, colInds) = A.nonzero()
     
     self.assertEquals(A.getnnz(), rowInds.shape[0])
     self.assertEquals(rowInds.shape[0], 0)
     self.assertEquals(colInds.shape[0], 0)
     
     (inds, ) = self.c.nonzero()   
     self.assertEquals(inds.shape[0], 0)
     
     #Zero size array 
     nrow = 0 
     ncol = 0
     A = csarray((nrow, ncol))
     (rowInds, colInds) = A.nonzero()
     self.assertEquals(A.getnnz(), rowInds.shape[0])
     self.assertEquals(rowInds.shape[0], 0)
     self.assertEquals(colInds.shape[0], 0)
     
     (inds, ) = self.d.nonzero()
     self.assertEquals(inds.shape[0], 0)
开发者ID:ElectronicRU,项目名称:sppy,代码行数:54,代码来源:csarrayTest.py


示例13: testNDim

    def testNDim(self):
        A = csarray((5, 7))
        self.assertEquals(A.ndim, 2)

        A = csarray((5, 7), storagetype="row")
        self.assertEquals(A.ndim, 2)

        A = csarray((0, 0))
        self.assertEquals(A.ndim, 2)

        self.assertEquals(self.a.ndim, 1)
        self.assertEquals(self.b.ndim, 1)
开发者ID:tguttenb,项目名称:MoMs-for-StochasticLanguages,代码行数:12,代码来源:csarrayTest.py


示例14: setUp

    def setUp(self):
        logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
        self.A = csarray((5, 5))

        nrow = 5 
        ncol = 7
        self.B = csarray((nrow, ncol))
        self.B[0, 1] = 1
        self.B[1, 3] = 5.2
        self.B[3, 3] = -0.2
        self.B[0, 6] = -1.23
        self.B[4, 4] = 12.2        
        
        nrow = 100 
        ncol = 100
        self.C = csarray((nrow, ncol))
        self.C[0, 1] = 1
        self.C[10, 3] = 5.2
        self.C[30, 34] = -0.2
        self.C[0, 62] = -1.23
        self.C[4, 41] = 12.2      
        
        self.D = csarray((5, 5))
        self.D[0, 0] = 23.1
        self.D[2, 0] = -3.1
        self.D[3, 0] = -10.0 
        self.D[2, 1] = -5 
        self.D[3, 1] = 5
        
        self.E = csarray((0, 0))
        
        self.F = csarray((6, 6), dtype=numpy.int)
        self.F[0, 0] = 23
        self.F[2, 0] = -3
        self.F[3, 0] = -10 
        self.F[2, 1] = -5 
        self.F[3, 1] = 5
        
        self.a = csarray(10, dtype=numpy.float)
        self.a[0] = 23 
        self.a[3] = 1.2
        self.a[4] = -8
        
        self.b = csarray(10, dtype=numpy.int)
        self.b[0] = 23 
        self.b[5] = 1
        self.b[8] = -8
        
        self.c = csarray((3, ), dtype=numpy.float)
        
        self.d = csarray((0, ), dtype=numpy.float)
开发者ID:ElectronicRU,项目名称:sppy,代码行数:51,代码来源:csarrayTest.py


示例15: testSetItem

 def testSetItem(self):
     nrow = 5 
     ncol = 7
     A = csarray((nrow, ncol))
     A[0, 1] = 1
     A[1, 3] = 5.2
     A[3, 3] = -0.2
     
     self.assertEquals(A[0, 1], 1)
     self.assertAlmostEquals(A[1, 3], 5.2)
     self.assertAlmostEquals(A[3, 3], -0.2)
     
     for i in range(nrow): 
         for j in range(ncol): 
             if (i, j) != (0, 1) and (i, j) != (1, 3) and (i, j) != (3, 3): 
                 self.assertEquals(A[i, j], 0)
     
     self.assertRaises(ValueError, A.__setitem__, (20, 1), 1)  
     self.assertRaises(TypeError, A.__setitem__, (1, 1), "a")   
     self.assertRaises(ValueError, A.__setitem__, (1, 100), 1)   
     self.assertRaises(ValueError, A.__setitem__, (-1, 1), 1)   
     self.assertRaises(ValueError, A.__setitem__, (0, -1), 1) 
     
     result = A[(numpy.array([0, 1, 3]), numpy.array([1, 3, 3]))] 
     self.assertEquals(result[0], 1)
     self.assertEquals(result[1], 5.2)
     self.assertEquals(result[2], -0.2)
     
     #Replace value of A 
     A[0, 1] = 2
     self.assertEquals(A[0, 1], 2)
     self.assertAlmostEquals(A[1, 3], 5.2)
     self.assertAlmostEquals(A[3, 3], -0.2)
     
     for i in range(nrow): 
         for j in range(ncol): 
             if (i, j) != (0, 1) and (i, j) != (1, 3) and (i, j) != (3, 3): 
                 self.assertEquals(A[i, j], 0)
                 
     #Try setting items with arrays 
     A = csarray((nrow, ncol))
     A[numpy.array([0, 1]), numpy.array([2, 3])] = numpy.array([1.2, 2.4])
     
     self.assertEquals(A.getnnz(), 2)
     self.assertEquals(A[0, 2], 1.2)
     self.assertEquals(A[1, 3], 2.4)
     
     A[numpy.array([2, 4]), numpy.array([2, 3])] = 5
     
     self.assertEquals(A[2, 2], 5)
     self.assertEquals(A[4, 3], 5)
开发者ID:phaustin,项目名称:sppy,代码行数:51,代码来源:csarrayTest.py


示例16: time_ns

def time_ns():
    density = 10**-3
    ns = var_range * 10**4
    times = numpy.zeros((5, ns.shape[0]))

    for i, n in enumerate(ns):
        # Generate random sparse matrix
        inds = numpy.random.randint(n, size=(2, n * n * density))
        data = numpy.random.rand(n * n * density)
        A = scipy.sparse.csc_matrix((data, inds), (n, n))
        A_sppy = sppy.csarray(A, storagetype="row")
        L = GeneralLinearOperator.asLinearOperator(A_sppy, parallel=True)
        print(A.shape, A.nnz)

        times[0, i] = time_reps(svds, (A, k), reps)
        times[1, i] = time_reps(svdp, (A, k), reps)
        # times[2, i] = time_reps(sparsesvd, (A, k), reps)
        times[3, i] = time_reps(truncated_svd.fit, (A,), reps)
        times[4, i] = time_reps(sppy.linalg.rsvd, (L, k, p, n_iter), reps)
        print(n, density, times[:, i])

    plt.figure(1)
    plt.plot(ns, times[0, :], 'k-', label="ARPACK")
    plt.plot(ns, times[1, :], 'r-', label="PROPACK")
    # plt.plot(ns, times[2, :], 'b-', label="SparseSVD")
    plt.plot(ns, times[3, :], 'k--', label="sklearn RSVD")
    plt.plot(ns, times[4, :], 'r--', label="sppy RSVD")
    plt.legend(loc="upper left")
    plt.xlabel("n")
    plt.ylabel("time (s)")
    plt.savefig("time_ns.png", format="png")
开发者ID:charanpald,项目名称:tyre-hug,代码行数:31,代码来源:svdbenchmark.py


示例17: epinions

    def epinions(minNnzRows=10, minNnzCols=3, quantile=90): 
        matrixFileName = PathDefaults.getDataDir() + "epinions/rating.mat" 
        A = scipy.io.loadmat(matrixFileName)["rating"]
        
        userIndexer = IdIndexer("i")
        itemIndexer = IdIndexer("i")        
        
        for i in range(A.shape[0]): 
            userIndexer.append(A[i, 0])
            itemIndexer.append(A[i, 1])


        rowInds = userIndexer.getArray()
        colInds = itemIndexer.getArray()
        ratings = A[:, 3]        
        
        X = sppy.csarray((len(userIndexer.getIdDict()), len(itemIndexer.getIdDict())), storagetype="row", dtype=numpy.int)
        X.put(numpy.array(ratings>3, numpy.int), numpy.array(rowInds, numpy.int32), numpy.array(colInds, numpy.int32), init=True)
        X.prune()
        
        X = SparseUtils.pruneMatrixRowAndCols(X, minNnzRows, minNnzCols)
        
        logging.debug("Read file: " + matrixFileName)
        logging.debug("Non zero elements: " + str(X.nnz) + " shape: " + str(X.shape))

        return X 
开发者ID:charanpald,项目名称:wallhack,代码行数:26,代码来源:DatasetUtils.py


示例18: generateSparseBinaryMatrix

 def generateSparseBinaryMatrix(shape, p, w=0.9, sd=0, csarray=False, verbose=False, indsPerRow=50):
     """
     Create an underlying matrix Z = UsV.T of rank p and then go through each row 
     and threshold so that a proportion quantile numbers are kept. The final matrix 
     is a 0/1 matrix. We order each row of Z in ascending order and then keep those bigger 
     than u. In other words w=0 keeps all numbers and w=1.0 keeps none. 
     """
     m, n = shape
     U, s, V = SparseUtils.generateLowRank(shape, p)
     
     X = (U*s).dot(V.T)
     
     wv = numpy.random.randn(m)*sd + w
     wv = numpy.clip(wv, 0, 1)
     r = SparseUtilsCython.computeR2((U*s), V, wv, indsPerRow=indsPerRow)
     
     for i in range(m):
         X[i, X[i, :] >= r[i]] = 1
         X[i, X[i, :] < r[i]] = 0
     
     if csarray:
         import sppy
         X = sppy.csarray(X, storagetype="row")
     else:
         X = scipy.sparse.csr_matrix(X)
         
     if verbose: 
         return X, U, s, V, wv 
     else: 
         return X
开发者ID:charanpald,项目名称:sandbox,代码行数:30,代码来源:SparseUtils.py


示例19: submatrix

    def submatrix(X, inds):
        """
        Take a sparse matrix in coo format and pick out inds indices relative to
        X.data. Returns a csc matrix.
        """
        if type(inds) != numpy.ndarray:
            inds = numpy.random.permutation(X.nnz)[0:inds]

        if scipy.sparse.issparse(X):
            rowInds, colInds = X.nonzero()
            rowInds = rowInds[inds]
            colInds = colInds[inds]
            vals = numpy.array(X[X.nonzero()]).ravel()[inds]
            
            if scipy.sparse.isspmatrix_csc(X): 
                return scipy.sparse.csc_matrix((vals, (rowInds, colInds)), X.shape)
            elif scipy.sparse.isspmatrix_csr(X): 
                return scipy.sparse.csr_matrix((vals, (rowInds, colInds)), X.shape)
        else:
            #Assume a sppy array
            rowInds, colInds = X.nonzero()
            rowInds = rowInds[inds]
            colInds = colInds[inds]
            vals = X.values()[inds]

            import sppy
            Y = sppy.csarray(X.shape, storagetype=X.storagetype, dtype=X.dtype)
            Y.put(vals, rowInds, colInds, init=True)
            return Y
开发者ID:charanpald,项目名称:sandbox,代码行数:29,代码来源:SparseUtils.py


示例20: profileDot

 def profileDot(self): 
     #Create random sparse matrix and numpy array 
     #Test speed of array creation 
     numpy.random.seed(21)
     m = 1000000
     n = 1000000      
     numInds = 10000000
     
     inds = numpy.random.randint(0, m*n, numInds)
     inds = numpy.unique(inds)
     vals = numpy.random.randn(inds.shape[0])
     
     rowInds, colInds = numpy.unravel_index(inds, (m, n), order="FORTRAN")
     rowInds = numpy.array(rowInds, numpy.int32)
     colInds = numpy.array(colInds, numpy.int32)
             
     A = csarray((m, n), storageType="rowMajor")
     A.put(vals, rowInds, colInds, True)
     A.compress()
     
     p = 500
     W = numpy.random.rand(n, p)
     
     
     ProfileUtils.profile('A.dot(W)', globals(), locals())
     
     #Compare versus scipy 
     #B = scipy.sparse.csc_matrix((vals, (rowInds, colInds)), (m, n))        
     #ProfileUtils.profile('B.dot(W)', globals(), locals())
     
     #Compare versus pdot       
     ProfileUtils.profile('A.pdot(W)', globals(), locals())
开发者ID:kburns,项目名称:sppy,代码行数:32,代码来源:csarrayProfile.py



注:本文中的sppy.csarray函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python workflow.Workflow类代码示例发布时间:2022-05-27
下一篇:
Python makeunicode.u函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap