且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

列表中的矩阵相乘

更新时间:2023-02-10 15:43:15

因此,通常来说,如何将两个列表的对应成员相乘?假设值的矩阵在list1中,而值0/1的矩阵在list2中,则使用lapply的方法之一

So generically, how do you multiply corresponding members of two lists? Suppose the matrices with values are in list1 and those with 0/1 are in list2, then one way to do it is with lapply

 answer <- lapply(seq_along(list1),FUN=function(i) list1[[i]]*list2[[i]])

您得到的矩阵将是answer的元素.

Your resulting matrices will be the elements of answer.