【发布时间】:2016-03-12 01:20:02
【问题描述】:
我正在使用下面的函数将 (row, col):value 形式的字典转换为 csr 矩阵。 row 和 col 是 int,value 是 float。
def convert(term_dict):
# Create the appropriate format for the COO format.
data = []
row = []
col = []
for k, v in term_dict.items():
r = int(k[0][1:])
c = int(k[1][1:])
data.append(v)
row.append(r-1)
col.append(c-1)
# Create the COO-matrix
coo = coo_matrix((data, (row, col)))
# Let Scipy convert COO to CSR format and return
return csr_matrix(coo)
来自here。我来了
r = int(k[0][1:]) TypeError: 'int' object has no attribute 'getitem'
【问题讨论】: