C语言实现协方差矩阵
最近在理解机器学习中的PCA降维算法,其中使用协方差矩阵。什么是些方差矩阵,这里不做多介绍。作为软件工程师,理解算法原理是一回事,没有亲自编码实践总觉得缺了什么。 现将自己C语言实现协方差矩阵代码如下 # include <stdio.h> # include <stdlib.h> # include <string.h> void TransposeMatrix ( int * input , int rows , int cols , int * output ) { for ( int row = 0 ; row < rows ; row ++ ) { for ( int col = 0 ; col < cols ; col ++ ) { int sindex = row * cols + col ; int dindex = col * rows + row ; printf ( "sindex=%d,dindex=%d\n" , sindex , dindex ) ; output [ dindex ] = input [ sindex ] ; } } } void PrintMatrix ( int * array , int rows , int cols ) { int index = 0 ; for ( int row = 0 ; row < rows ; row