I have a block matrix of size 4*4
Blockmatrix =
0.0 2.0 1.0 2.0
2.0 0.0 2.0 4.0
1.0 2.0 0.0 3.0
2.0 4.0 3.0 0.0
While typing the type of this matrix,
It is showing
<class 'pyspark.mllib.linalg.distributed.BlockMatrix'>
I want to change only the diagonal element to 1.0.
When I tried this piece of code,
diagonal_matrix = DenseMatrix(dataframe_item.numRows,dataframe_item.numCols,dataframe_item.toLocalMatrix().rowIter().zipWithIndex().flatMap(lambda x:(x[1].toArray(x[2]),x[1].toArray())).toArray())
It is throwing the following error,
AttributeError: 'DenseMatrix' object has no attribute 'rowIter'
Can anyone help to solve this error? Or is there any better way to change diagonal values of BlockMatrix in Pyspark?