大型矩阵的Kronecker产品 [英] Kronecker product for large matrices

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

问题描述

我正在寻找一种有效的方法来计算两个大型矩阵的Kronecker乘积.我尝试使用方法kronecker()如下:

I am looking for an effficient way of computing the Kronecker product of two large matrices. I have tried using the method kronecker() as follows:

 I = diag(700)
 data = replicate(15, rnorm(120))
 test = kronecker(I,data)

但是,执行需要很长时间,然后出现以下错误:

However, it takes a long time to execute and then gives the following error:

 Error: cannot allocate vector of size 6.8 Gb

推荐答案

只要使用Matrix::Diagonal构造对角矩阵,就会自动将test对象构造为稀疏矩阵:

As long as you use Matrix::Diagonal to construct your diagonal matrix, you'll automatically get your test object constructed as a sparse matrix:

library(Matrix)
I=Diagonal(700)
data = replicate(15,rnorm(120))
system.time(test <- kronecker(I,data))
##   user  system elapsed
##  0.600   0.044   0.671 
dim(test)
## [1] 84000 10500
format(object.size(test),"Mb")
## [1] "19.2 Mb"

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

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