⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.h

📁 不用任何更改即可运行的神经网络程序 包括矩阵类和神经网络类和主函数
💻 H
字号:
#ifndef		_michael_matrix_
#define		_michael_matrix_

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <windows.h>
#include <iostream.h>

class CMatrix 
{
private:
	int		m_numRows;
	int		m_numCols;
public:
	double*  m_value;
public:
	int		rows();
	int		cols();
	void	setRows(int rows);
	void	setCols(int cols);
	double& r(int index);
	double& r(int rows, int cols);
	
	CMatrix&	operator = (   CMatrix& sample);
	CMatrix( CMatrix&);
	CMatrix(){m_value = NULL;}

};
double& CMatrix::r(int index)
{
	return m_value[index-1];
}
double& CMatrix::r(int rows, int cols)
{
	return m_value[(rows-1)*m_numCols + cols-1];
}
CMatrix	zeros(int numrows, int numcols=1)
{
	CMatrix matrix;
	matrix.setRows(numrows);
	matrix.setCols(numcols);
	matrix.m_value = new double[numrows*numcols];
	ZeroMemory(matrix.m_value,numrows*numcols*sizeof(double));
	return matrix;
}
void CMatrix::setRows(int rows)
{
	m_numRows = rows;
}
void CMatrix::setCols(int cols)
{
	m_numCols = cols;
}
int	CMatrix::rows()
{
	return	m_numRows;
}
int CMatrix::cols()
{
	return	m_numCols;
}

CMatrix& CMatrix::operator =(  CMatrix& sample)
{
	if(m_value)
	delete []m_value;
	m_value = new double[sample.m_numRows*sample.m_numCols];
	ZeroMemory(m_value, sample.m_numCols*sample.m_numRows*sizeof(double));
	m_numRows = sample.rows();
	m_numCols = sample.cols();
	for(int i=0;i<m_numRows;i++)
		for(int j=0;j<m_numCols;j++)
		{
			m_value[i*m_numCols + j] = sample.m_value[i*m_numCols + j];
		}
	return *this;
}
CMatrix::CMatrix( CMatrix& matrix)
{
	m_numRows = matrix.rows();
	m_numCols = matrix.cols();
	m_value = new double[m_numRows*m_numCols];
	memcpy(m_value,matrix.m_value,m_numRows*m_numCols*sizeof(double));
}

#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -