![](/img/trans.png)
[英]Is there a way to calculate similarity between one sparse vector and matrix?
[英]Calculate Similarity of Sparse Matrix
我正在使用Python与numpy,scipy和scikit-learn模块。
我想用非常大的稀疏矩阵对数组进行分类。 (100,000 * 100,000)
矩阵中的值等于0或1.我唯一拥有的是value = 1的索引。
a = [1,3,5,7,9]
b = [2,4,6,8,10]
意思是
a = [0,1,0,1,0,1,0,1,0,1,0]
b = [0,0,1,0,1,0,1,0,1,0,1]
如何在scipy中将索引数组更改为稀疏数组?
如何快速对这些阵列进行分类?
非常感谢你。
如果您选择稀疏的coo_matrix
您可以通过以下索引创建它:
from scipy.sparse import coo_matrix
import scipy
nrows = 100000
ncols = 100000
row = scipy.array([1,3,5,7,9])
col = scipy.array([2,4,6,8,10])
values = scipy.ones(col.size)
m = coo_matrix((values, (row,col)), shape=(nrows, ncols), dtype=float)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.