線性代數-矩陣-轉置 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.pswp.cn/news/391807.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391807.shtml
英文地址,請注明出處:http://en.pswp.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 的元素。如果…