0

我正在研究具有以下内容的算法

  A = np.array([[10,  5, 1, 0, 0],
          [6, 6, 0, 1, 0],
          [4.5, 18,0, 0, 1]])

 nonbasis = np.array([0, 1])
 basis = np.array([2, 3, 4])

我正在执行以下操作以根据上面给定的信息创建 BlockMatrix。

dm2 = Matrices.dense(3, 2, A[:, nonbasis].flatten().tolist())

blocks2 = sc.parallelize([((0, 0), dm2)])

mat3 = BlockMatrix(blocks2, 3, 2)

我期待mat3如下,

mat3 = DenseMatrix([[ 10. ,   5. ],
         [  6. ,   6.],
         [  4.5 ,  18. ]])

我得到的结果是,

mat3 = DenseMatrix([[ 10. ,   6. ],
         [  5. ,   4.5],
         [  6. ,  18. ]])

理想情况下,如果它是 3X3 矩阵或 nxm,其中 n=m,那么我会使用 mat3 =mat3.transpose()。

在这里,如果我这样做,那么 2X3 矩阵将变为 3X2,这会在我的算法中进一步产生问题。任何人都可以提出一个简单的解决方案。

4

1 回答 1

0

我会选择中间IndexedRowMatrix

from pyspark.mllib.linalg.distributed import IndexedRowMatrix

IndexedRowMatrix(sc.parallelize(enumerate(A))).toBlockMatrix()
于 2017-07-28T14:22:04.680 回答