MyMediaLite.DataType.SparseBooleanMatrix.Transpose C# (CSharp) Method

Transpose() public method

Get the transpose of the matrix, i.e. a matrix where rows and columns are interchanged
public Transpose ( ) : IMatrix
return IMatrix
        public IMatrix<bool> Transpose()
        {
            var transpose = new SparseBooleanMatrix();
            for (int i = 0; i < row_list.Count; i++)
                foreach (int j in this[i])
                    transpose[j, i] = true;
            return transpose;
        }

Usage Example

		[Test()] public void TestTranspose()
		{
			var matrix = new SparseBooleanMatrix();
			for (int i = 0; i < 7; i++)
				if(i != 2 && i != 4)
				{
					matrix[i, 1] = true;
					matrix[i, 4] = true;
				}
			matrix[2, 2] = true;
			matrix[2, 5] = true;
			matrix[4, 3] = true;
			// transpose the matrix
			var transposed_matrix = (IBooleanMatrix) matrix.Transpose();
			// test the transposed matrix
			Assert.IsTrue(transposed_matrix[1,0]);
			Assert.IsTrue(transposed_matrix[4, 6]);
			Assert.IsFalse(transposed_matrix[3, 1]);
			Assert.IsFalse(transposed_matrix[5, 4]);
		}
All Usage Examples Of MyMediaLite.DataType.SparseBooleanMatrix::Transpose