R:稀疏矩阵乘法与data.table和quanteda包? [英] R: sparse matrix multiplication with data.table and quanteda package?
本文介绍了R:稀疏矩阵乘法与data.table和quanteda包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个矩阵雕刻与稀疏矩阵和包称为quanteda,利用data.table包,与此线程相关在这里。
I am trying to create a matrix mulptiplication with sparse matrix and with the package called quanteda, utilising data.table package, related to this thread here. So
require(quanteda)
mytext <- c("Let the big dogs hunt", "No holds barred", "My child is an honor student")
myMatrix <-dfm(mytext, ignoredFeatures = stopwords("english"), stem = TRUE) #a data.table
as.matrix(myMatrix) %*% transpose(as.matrix(myMatrix))
在这里用quanteda包和稀疏矩阵得到矩阵乘法?
how can you get the matrix multiplication working here with quanteda package and sparse matrices?
推荐答案
这很好:
mytext <- c("Let the big dogs hunt",
"No holds barred",
"My child is an honor student")
myMatrix <- dfm(mytext)
myMatrix %*% t(myMatrix)
## 3 x 3 sparse Matrix of class "dgCMatrix"
## text1 text2 text3
## text1 5 . .
## text2 . 3 .
## text3 . . 6
无需使用 as.matrix
。注意,它不再是一个dfmSparse对象,因为它不再是特征的文档矩阵。
No need to coerce to a dense matrix using as.matrix()
. Note that it is no longer a "dfmSparse" object because it's no longer a matrix of documents by features.
这篇关于R:稀疏矩阵乘法与data.table和quanteda包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文