Scipy.sparse-lil_matrix乘法不起作用

时间:2019-06-08 09:08:37

标签: python scipy sparse-matrix

我尝试通过sparse包中的lil_matrixscipy.sparse生成随机马尔可夫矩阵:

markov = lil_matrix((n, n), dtype=float)

for i in range(n):
    entries = random.randrange(5, 10 + 1, 1)
    for j in range(entries):
        pos = random.randrange(0, n, 1)
        while markov[pos, i] != 0:
            pos = random.randrange(0, n, 1)
        markov[pos, i] = 1.0 / entries

ones = lil_matrix((n, n), dtype=float)
ones.data[:] = 0.15 * (1.0 / n)

fac = lil_matrix((n, n), dtype=float)
fac.data[:] = (1 - 0.15)

left = markov.multiply(fac) #<- fails!

但是最后一行代码失败:

TypeError: 'float' object is not iterable

那是为什么?

0 个答案:

没有答案