线性代数-矩阵-转置 C和C++的实现

原理解析:

本节介绍矩阵的转置。矩阵的转置即将矩阵的行和列元素调换,即原来第二行第一列(用C21表示,后同)与第一行第二列(C12)元素调换位置,原来c31与C13调换。即cij与cji调换 。

(此处补图说明)

C++语言:

首先我们想到的是把第i行第j列取出来与第j行第i列调换,这种思路很简单就不多说了。

这里提供另一个思路,对整行整列进行操作,方法如下:

  1. 使用getSpecifiedRow()把本矩阵中的第i行取出来放在向量tempVec中;
  2. 使用 addOneColumToBack()把上述取出来的tempVec放入临时矩阵tempMatrix的列中;
  3. 用临时tempMatrix取代本矩阵;
template <typename T>
Matrix<T> Matrix<T>::transpose()
{Matrix<T> tempMatrix;vector<T> tempVec;/*get transpose*/for(int i=0;i<m_iColumns;i++){this->getSpecifiedRow(i,&tempVec);tempMatrix.addOneColumToBack(tempVec);}/*swap rows and columns*/m_vecMatrix = tempMatrix.m_vecMatrix;int temp = m_iColumns;m_iColumns = m_iRows;m_iRows = temp;return tempMatrix;
}

 

转载于:https://www.cnblogs.com/HongYi-Liang/p/7287495.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/391807.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

数字经济的核心是对大数据_大数据崛起为数字世界的核心润滑剂

数字经济的核心是对大数据“Information is the oil of the 21st century, and analytics is the combustion engine”.“信息是21世纪的石油&#xff0c;分析是内燃机”。 — Peter Sondergaard, Senior Vice President of Gartner Research.— Gartner研究部高级副总裁Peter…

乞力马扎罗山 海明威_我如何对海明威编辑器(一种流行的写作应用程序)进行反向工程,并从泰国的海滩上构建了自己的数据库

乞力马扎罗山 海明威I’ve been using the Hemingway App to try to improve my posts. At the same time I’ve been trying to find ideas for small projects. I came up with the idea of integrating a Hemingway style editor into a markdown editor. So I needed to fi…

leetcode 566. 重塑矩阵

在MATLAB中&#xff0c;有一个非常有用的函数 reshape&#xff0c;它可以将一个矩阵重塑为另一个大小不同的新矩阵&#xff0c;但保留其原始数据。 给出一个由二维数组表示的矩阵&#xff0c;以及两个正整数r和c&#xff0c;分别表示想要的重构的矩阵的行数和列数。 重构后的…

制作简单的WIFI干扰器

原教程链接:http://www.freebuf.com/geek/133161.htmlgithub 1.准备材料 制作需要的材料有 nodemcu开发版IIC通信 128*64 OLED液晶屏电线按钮开关万能板排针(自选)双面胶(自选)参考2.准备焊接 引脚焊接参考 oled按钮效果3.刷入固件 下载烧录工具:ESP8266Flasher.exe 下载固件:…

Snipaste截图

绘图绘色&#xff0c;描述加图片能更加说明问题的本质。今天推荐一款多功能的截图snipaste... 欣赏绘色 常见报错 解决方案&#xff1a; 下载相关的DLL即可解决&#xff0c; 请根据你操作系统的版本&#xff08;32位/64位&#xff09;&#xff0c;下载并安装相应的微软 Visual …

azure第一个月_MLOps:两个Azure管道的故事

azure第一个月Luuk van der Velden and Rik Jongerius卢克范德费尔登(Luuk van der Velden)和里克 琼格里乌斯( Rik Jongerius) 目标 (Goal) MLOps seeks to deliver fresh and reliable AI products through continuous integration, continuous training and continuous del…

firebase auth_如何使用auth和实时数据库构建Firebase Angular应用

firebase authby Zdravko Kolev通过Zdravko Kolev 如何使用auth和实时数据库构建Firebase Angular应用 (How to build a Firebase Angular app with auth and a real-time database) For a long time, I was looking for a good Portfolio web app that can help me to easily…

Mybatis—多表查询

Mybatis多表查询 一对一查询 一对一查询的模型MapperScannerConfigurer 用户表和订单表的关系为&#xff0c;一个用户有多个订单&#xff0c;一个订单只从属于一个用户 创建Order和User实体 public class Order {private int id;private Date ordertime;private double to…

VS2008 开发设计MOSS工作流 URN 注意了

最近学习MOSS 很苦恼&#xff0c;进度也很慢&#xff0c;最近在学习VS2008开发工作流&#xff0c;其中有结合INFOPATH 2007来做, 出现个BUG或者说是设置的问题,整整花了我一天工作时间&#xff0c;是这样的: 在部署的时候关于URN&#xff0c;大部分的教程都是这样的说的&#…

ArangoDB Foxx service 使用

备注&#xff1a;项目使用的是github https://github.com/arangodb-foxx/demo-hello-foxx1. git clonegit clone https://github.com/arangodb-foxx/demo-hello-foxx.git 2. 安装foxx servicefoxx-manager install demo-hello-foxx /demoapp 3. 效果自动生成的swagger 文档项目…

编译原理 数据流方程_数据科学中最可悲的方程式

编译原理 数据流方程重点 (Top highlight)Prepare a box of tissues! I’m about to drop a truth bomb about statistics and data science that’ll bring tears to your eyes.准备一盒纸巾&#xff01; 我将投放一本关于统计和数据科学的真相炸弹&#xff0c;这会让您眼泪汪…

@ConTrollerAdvice的使用

ConTrollerAdvice&#xff0c;从名字上面看是控制器增强的意思。 在javaDoc写到/*** Indicates the annotated class assists a "Controller".** <p>Serves as a specialization of {link Component Component}, allowing for* implementation classes to be a…

Mybatis—注解开发

Mybatis的注解开发 MyBatis的常用注解 这几年来注解开发越来越流行&#xff0c;Mybatis也可以使用注解开发方式&#xff0c;这样我们就可以减少编写Mapper映射文件了。 Insert&#xff1a;实现新增 Update&#xff1a;实现更新 Delete&#xff1a;实现删除 Select&#x…

道路工程结构计算软件_我从软件工程到产品管理的道路

道路工程结构计算软件by Sari Harrison莎莉哈里森(Sari Harrison) 我从软件工程到产品管理的道路 (My path from software engineering to product management) 以及一些有关如何自己做的建议 (And some advice on how to do it yourself) I am often asked how to make the m…

Vue 指令

下面列举VUE的HTML页面模板指令&#xff0c;并进行分别练习。 1. templates 2. v-if, v-for <div idapp><ol><li v-for"todo in todos>{{ todo.text}}</li></ol> </div><script>app new Vue({ el: #app, data: { return…

iOS-FMDB

2019独角兽企业重金招聘Python工程师标准>>> #import <Foundation/Foundation.h> #import <FMDatabase.h> #import "MyModel.h"interface FMDBManager : NSObject {FMDatabase *_dataBase; }(instancetype)shareInstance;- (BOOL)insert:(MyM…

解决朋友圈压缩_朋友中最有趣的朋友[已解决]

解决朋友圈压缩We live in uncertain times.我们生活在不确定的时代。 We don’t know when we’re going back to school or the office. We don’t know when we’ll be able to sit inside at a restaurant. We don’t even know when we’ll be able to mosh at a Korn co…

西安项目分析

西安物流 西安高考补习 西安艺考 转载于:https://www.cnblogs.com/wpxuexi/p/7294269.html

MapServer应用开发平台示例

MapServer为当前开源WebGIS的应用代表&#xff0c;在西方社会应用面极为广泛&#xff0c;现介绍几个基于它的开源应用平台。 1.GeoMOOSE GeoMoose is a Web Client Javascript Framework for displaying distributed cartographic data. Among its many strengths, it can hand…

leetcode 995. K 连续位的最小翻转次数(贪心算法)

在仅包含 0 和 1 的数组 A 中&#xff0c;一次 K 位翻转包括选择一个长度为 K 的&#xff08;连续&#xff09;子数组&#xff0c;同时将子数组中的每个 0 更改为 1&#xff0c;而每个 1 更改为 0。 返回所需的 K 位翻转的最小次数&#xff0c;以便数组没有值为 0 的元素。如果…