两个矩阵相加 [英] addition of two matrices

查看:113
本文介绍了两个矩阵相加的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我们可以添加两个不同大小的矩阵吗?如果是,怎么办?



can we add two different size matrices? if yes, how?

推荐答案

这完全取决于您的定义. 传统"矩阵代数中没有这样的运算,但是您可以定义自己的运算.

例如,这是一种很自然的方法:您可以创建新的矩阵,并将其尺寸构建为每个操作数矩阵的最大尺寸.如果操作数矩阵相交,则用操作数的元素(单元)之和填充结果矩阵.对于仅定义了一个操作数矩阵的索引,请填充其值;所有其他单元格(如果有的话)都填充一些默认值.

是否要为singledouble浮点类型提供一个好的默认值? NaN的值.那呢?

—SA
It totally depends on your definition. There is no such operation in "traditional" matrix algebra, but you can define your own operations.

For example, this is one pretty natural way: you can create the new matrix with dimensions built as maximums of dimensions of each operand matrices. Where operand matrices intersects, fill the resulting matrix with the sums of the elements (cells) of the operands; for the indexes where only one of the operand matrix is defined, fill with its values; all other cells, if any, fill with some default value.

Do you want a good default value for single or double floating-point types? The values of NaN. How about that?

—SA


这篇关于两个矩阵相加的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆