
矩阵乘法
现在讨论矩阵乘法的过程。矩阵乘法只有满足一定的条件才能进行。假设两个矩阵是 P 和 Q,它们的维度是 P (a x b) 和 Q (z x y),当且仅当 b = x 时才能找到结果矩阵。那么所得矩阵 R 的阶将为 (m x q)。
算法
matrixMultiply(P, Q):Assume dimension of P is (a x b), dimension of Q is (z x y)Begin if b is not same as z, then exit otherwise define R matrix as (a x y) for i in range 0 to a - 1, do for j in range 0 to y – 1, do for k in range 0 to z, do R[i, j] = R[i, j] + (P[i, k] * Q[k, j]) done done doneEnd
矩阵标准化
Suppose we have a 2x3 matrix:4 5 61 2 3 The normalized matrix would be:4/sqrt(pow(5,2) + pow(6,2)) 5/sqrt(pow(5,2) + pow(6,2)) 6/sqrt(pow(5,2) + pow(6,2))1/sqrt(pow(2,2) + pow(3,2)) 2/sqrt(pow(2,2) + pow(3,2)) 3/sqrt(pow(2,2) + pow(3,2))
示例
#include #include
输出
Enter size of a matrix23Enter matrix of size 2X34 5 61 2 3rows: 2 cols: 3 elements:4 5 61 2 3Sum of squares of row 0: 61Sum of squares of row 1: 13Normalized Matrix:0.512 0.640 0.7680.277 0.555 0.832Process returned 0 (0x0) execution time : 12.446 sPress any key to continue.
以上就是矩阵乘法和归一化在C程序中的实现的详细内容,更多请关注创想鸟其它相关文章!
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。
如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 chuangxiangniao@163.com 举报,一经查实,本站将立刻删除。
发布者:程序猿,转转请注明出处:https://www.chuangxiangniao.com/p/1444525.html
微信扫一扫
支付宝扫一扫