3.7. Matrix operations

3.7.1. igraph_matrix_add_constant — Add a constant to every element.
3.7.2. igraph_matrix_scale — Multiplies each element of the matrix by a constant.
3.7.3. igraph_matrix_add — Add two matrices.
3.7.4. igraph_matrix_sub — Difference of two matrices.
3.7.5. igraph_matrix_mul_elements — Elementwise multiplication.
3.7.6. igraph_matrix_div_elements — Elementwise division.
3.7.7. igraph_matrix_sum — Sum of elements
3.7.8. igraph_matrix_prod — Product of the elements.
3.7.9. igraph_matrix_rowsum — Rowwise sum
3.7.10. igraph_matrix_colsum — Columnise sum
3.7.11. igraph_matrix_transpose — Transpose

3.7.1. igraph_matrix_add_constant — Add a constant to every element.

void igraph_matrix_add_constant(igraph_matrix_t *m, igraph_real_t plus);

Arguments: 

m:

The input matrix.

plud:

The constant to add.

Time complexity: O(mn), the number of elements.

3.7.2. igraph_matrix_scale — Multiplies each element of the matrix by a constant.

void igraph_matrix_scale(igraph_matrix_t *m, igraph_real_t by);

Arguments: 

m:

The matrix.

by:

The constant.

Added in version 0.2.

Time complexity: O(n), the number of elements in the matrix.

3.7.3. igraph_matrix_add — Add two matrices.

int igraph_matrix_add(igraph_matrix_t *m1, 
				const igraph_matrix_t *m2);

Add m2 to m1, and store the result in m1. The size of the matrices must match.

Arguments: 

m1:

The first matrix, the result will be stored here.

m2:

The second matrix, it is left unchanged.

Returns: 

Error code.

Time complexity: O(mn), the number of elements.

3.7.4. igraph_matrix_sub — Difference of two matrices.

int igraph_matrix_sub(igraph_matrix_t *m1, 
				const igraph_matrix_t *m2);

Subtract m2 from m1 and store the result in m1. The size of the two matrices must match.

Arguments: 

m1:

The first matrix, the result is stored here.

m2:

The second matrix, it is left unchanged.

Returns: 

Error code.

Time complexity: O(mn), the number of elements.

3.7.5. igraph_matrix_mul_elements — Elementwise multiplication.

int igraph_matrix_mul_elements(igraph_matrix_t *m1, 
					 const igraph_matrix_t *m2);

Multiply m1 by m2 elementwise and store the result in m1. The size of the two matrices must match.

Arguments: 

m1:

The first matrix, the result is stored here.

m2:

The second matrix, it is left unchanged.

Returns: 

Error code.

Time complexity: O(mn), the number of elements.

3.7.6. igraph_matrix_div_elements — Elementwise division.

int igraph_matrix_div_elements(igraph_matrix_t *m1, 
					 const igraph_matrix_t *m2);

Divide m1 by m2 elementwise and store the result in m1. The size of the two matrices must match.

Arguments: 

m1:

The divident. The result is store here.

m2:

The divisor. It is left unchanged.

Returns: 

Error code.

Time complexity: O(mn), the number of elements.

3.7.7. igraph_matrix_sum — Sum of elements

igraph_real_t igraph_matrix_sum(const igraph_matrix_t *m);

Returns the sum of the elements of a matrix.

Arguments: 

m:

The input matrix.

Returns: 

The sum of the elements.

Time complexity: O(mn), the number of elements in the matrix.

3.7.8. igraph_matrix_prod — Product of the elements.

igraph_real_t igraph_matrix_prod(const igraph_matrix_t *m);

Note this function can result an overflow easily, even for not too big matrices.

Arguments: 

The:

input matrix.

Returns: 

The product of the elements.

Time complexity: O(mn), the number of elements.

3.7.9. igraph_matrix_rowsum — Rowwise sum

int igraph_matrix_rowsum(const igraph_matrix_t *m,
				   igraph_vector_t *res);

Calculate the sum of the elements in each row.

Arguments: 

m:

The input matrix.

res:

Pointer to an initialized vector, the result is stored here. It will be resized if necessary.

Returns: 

Error code.

Time complexity: O(mn), the number of elements in the matrix.

3.7.10. igraph_matrix_colsum — Columnise sum

int igraph_matrix_colsum(const igraph_matrix_t *m,
				   igraph_vector_t *res);

Calculate the sum of the elements in each column.

Arguments: 

m:

The input matrix.

res:

Pointer to an initialized vector, the result is stored here. It will be resized if necessary.

Returns: 

Error code.

Time complexity: O(mn), the number of elements in the matrix.

3.7.11. igraph_matrix_transpose — Transpose

int igraph_matrix_transpose(igraph_matrix_t *m);

Calculate the transpose of a matrix. Note that the function reallocates the memory used for the matrix.

Arguments: 

m:

The input (and output) matrix.

Returns: 

Error code.

Time complexity: O(mn), the number of elements in the matrix.