Skip to content

sum_matrixSumMatrixSumMatrixsum_matrixT_sum_matrix🔗

Short description🔗

sum_matrixSumMatrixSumMatrixsum_matrixT_sum_matrix — Returns the elementwise sum of a matrix.

Signature🔗

sum_matrix( matrix MatrixID, string SumType, out matrix MatrixSumID )void SumMatrix( const HTuple& MatrixID, const HTuple& SumType, HTuple* MatrixSumID )static void HOperatorSet.SumMatrix( HTuple matrixID, HTuple sumType, out HTuple matrixSumID )def sum_matrix( matrix_id: HHandle, sum_type: str ) -> HHandle

Herror T_sum_matrix( const Htuple MatrixID, const Htuple SumType, Htuple* MatrixSumID )

HMatrix HMatrix::SumMatrix( const HString& SumType ) const

HMatrix HMatrix::SumMatrix( const char* SumType ) const

HMatrix HMatrix::SumMatrix( const wchar_t* SumType ) const (Windows only)

HMatrix HMatrix.SumMatrix( string sumType )

Description🔗

The operator sum_matrixSumMatrix returns the sum of the elements of the Matrix defined by the matrix handle MatrixIDmatrixIDmatrix_id. A new matrix MatrixSum is generated with the result and the matrix handle MatrixSumIDmatrixSumIDmatrix_sum_id of this matrix is returned. Access to the elements of the matrix is possible e.g., with the operator get_full_matrixGetFullMatrix.

The type of sum determination of the matrix can be selected via the parameter SumTypesumTypesum_type:

  • 'columns'"columns": The sum is returned for each column of the Matrix separately. The resulting matrix MatrixSum has one row and the identical number of columns as the input matrix.

    Example:

    SumTypesumTypesum_type = 'columns'"columns"

    \[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrr} 8.0 & 4.0 & -3.0 \\ -6.0 & 2.0 & 7.0 \end{array} \right] \end{eqnarray*}\]
    \[\begin{eqnarray*} \to \qquad \texttt{MatrixSum} = \left[ \begin{array}{rrr} 2.0 & 6.0 & 4.0 \\ \end{array} \right] \end{eqnarray*}\]
  • 'rows'"rows": The sum is returned for each row of the Matrix separately. The resulting matrix MatrixSum has the identical number of rows as the input matrix and one column.

    Example:

    SumTypesumTypesum_type = 'rows'"rows"

    \[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrr} 8.0 & 4.0 & -3.0 \\ -6.0 & 2.0 & 7.0 \end{array} \right] \end{eqnarray*}\]
    \[\begin{eqnarray*} \to \qquad \texttt{MatrixSum} = \left[ \begin{array}{r} 9.0 \\ 3.0 \end{array} \right] \end{eqnarray*}\]
  • 'full'"full": The sum is returned using all elements of the Matrix. The resulting matrix MatrixSum has one row and one column.

    Example:

    SumTypesumTypesum_type = 'full'"full"

    \[\begin{eqnarray*} \texttt{Matrix} = \left[ \begin{array}{rrr} 8.0 & 4.0 & -3.0 \\ -6.0 & 2.0 & 7.0 \end{array} \right] \end{eqnarray*}\]
    \[\begin{eqnarray*} \to \qquad \texttt{MatrixSum} = \left[ \begin{array}{r} 12.0 \\ \end{array} \right] \end{eqnarray*}\]

Execution information🔗

Execution information
  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).

  • Multithreading scope: global (may be called from any thread).

  • Processed without parallelization.

Parameters🔗

MatrixIDmatrixIDmatrix_id (input_control) matrix → (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)

Matrix handle of the input matrix.

SumTypesumTypesum_type (input_control) string → (string)HTuple (HString)HTuple (string)strHtuple (char*)

Type of summation.

Default: 'columns'"columns"
List of values: 'columns', 'full', 'rows'"columns", "full", "rows"

MatrixSumIDmatrixSumIDmatrix_sum_id (output_control) matrix → (handle)HTuple (HHandle)HMatrix, HTuple (IntPtr)HHandleHtuple (handle)

Matrix handle with the sum of the input matrix.

Result🔗

If the parameters are valid, the operator sum_matrixSumMatrix returns the value 2 (H_MSG_TRUE). If necessary, an exception is raised.

Combinations with other operators🔗

Combinations

Possible predecessors

create_matrixCreateMatrix

Possible successors

get_full_matrixGetFullMatrix, get_value_matrixGetValueMatrix

See also

norm_matrixNormMatrix

Module🔗

Foundation