一般矩阵的转置

矩阵A转置为矩阵B,采用优化方法实现,对A矩阵,采用行指针*Arow访问同一行不同列元素,对矩阵B,采用列指针*Bptr访问相同列不同行元素。

代码实现

void transpose(int a[3][4],int b[4][3]);

void transpose(int a[3][4],int b[4][3])

{

int i,j;

int *Arow;

int *Bptr;

for(i=0;i<3;i++)

{

Arow=&a[i][0];

Bptr=&b[0][i];

for(j=0;j<4;j++)

{

*Bptr=Arow[j];

Bptr+=3;

}

}

}

void main()

{

int a[3][4],b[4][3];

int i,j;

for(i=0;i<3;i++)

for(j=0;j<4;j++)

a[i][j]=i+j+1;

transpose(a,b);

}

运行结果

一般方法

void transpose(int a[3][4],int b[4][3]);

void transpose(int a[3][4],int b[4][3])

{

int i,j;

for(i=0;i<3;i++)

for(j=0;j<4;j++)

b[j][i]=a[i][j];

}

void main()

{

int a[3][4],b[4][3];

int i,j;

for(i=0;i<3;i++)

for(j=0;j<4;j++)

a[i][j]=i+j+3+4;

transpose(a,b);

}

相关推荐
我是苏苏21 小时前
C#高级:程序查询写法性能优化提升策略(附带Gzip算法示例)
开发语言·算法·c#
sali-tec1 天前
C# 基于halcon的视觉工作流-章56-彩图转云图
人工智能·算法·计算机视觉·c#
梦想画家1 天前
基于PyTorch的时间序列异常检测管道构建指南
人工智能·pytorch·python
Elastic 中国社区官方博客1 天前
在 Elasticsearch 中使用 Mistral Chat completions 进行上下文工程
大数据·数据库·人工智能·elasticsearch·搜索引擎·ai·全文检索
一碗绿豆汤1 天前
机器学习第二阶段
人工智能·机器学习
用什么都重名1 天前
DeepSeek-OCR 深度解析
人工智能·ocr·deepseek-ocr
河南骏1 天前
RAG_检索进阶
人工智能·深度学习
灯火不休时1 天前
95%准确率!CNN交通标志识别系统开源
人工智能·python·深度学习·神经网络·cnn·tensorflow
mit6.8241 天前
[手机AI开发sdk] Aid_code IDE | PC浏览器同步访问
ide·人工智能·智能手机
deephub1 天前
FastMCP 入门:用 Python 快速搭建 MCP 服务器接入 LLM
服务器·人工智能·python·大语言模型·mcp