0
如果数组以dB为单位存在,我想检查if语句。到目前为止,我在光标中检查上述语句,但我猜测它会降低查询速度。我的代码到现在为止是:检查mongodB中是否存在元素
编辑: 线= [line.rstrip()线路开放(INPUT_FILE)
print len(lines)
row_no = len(lines)
col_no = len(lines)
matrix = sparse.lil_matrix((len(lines), len(lines)))
no_row = 0
counter = 0
for item in lines:
# find from database those items which their id exists in lines list and contain a follower_list
for cursor in collection.find({"_id.uid": int(item)}):
if cursor['list_followers'] is None:
continue
else:
id = cursor['_id']['uid']
counter+=1
print counter
print id
name = cursor['screenname']
# text.write('%s \n' %name)
followers = cursor['list_followers']
print len(followers)
for follower in followers:
try:
if (follower in lines) and (len(followers)>0):
matrix[no_row, lines.index(follower)] = 1
print no_row, " ", lines.index(follower), " ", matrix[no_row, lines.index(follower)]
except ValueError:
continue
no_row+=1
print no_row
scipy.io.mmwrite(output_file, matrix, field='integer')
最后我发现,延误是由于创建稀疏的.lil_matrix
不知道我是否在跟踪这个问题。您是否要求以最有效的方式查看文档中是否存在数组字段,并确实有一些内容? –
“,但我猜测*它会降低查询速度” - 这就是问题所在, –
是的,这就是我的问题! –