这是代码:
import numpy as np
# sigmoid function
def nonlin(x,deriv=False):
if(deriv==True):
return x*(1-x)
return 1/(1+np.exp(-x))
# input dataset
X = np.array([ [0,0,1],
[0,1,1],
[1,0,1],
[1,1,1] ])
# output dataset
y = np.array([[0,0,1,1]]).T
# seed random numbers to make calculation
# deterministic (just a good practice)
np.random.seed(1)
# initialize weights randomly with mean 0
syn0 = 2*np.random.random((3,1)) - 1
for iter in xrange(10000):
# forward propagation
l0 = X
l1 = nonlin(np.dot(l0,syn0))
# how much did we miss?
l1_error = y …Run Code Online (Sandbox Code Playgroud) 在执行 find() 查询时,我可以传递限制和排序等选项。我认为,这意味着数据库将在找到有限数量的文档后停止尝试过滤匹配文档。
当尝试使用聚合管道完成相同的事情时,我将 find() 中的相同查询作为 $match 阶段,但我无法指定限制。
$limit 的问题在于它只发生在下一阶段,因此 mongo 将在将集合中的每个文档传递到下一阶段之前处理它,随着集合大小的增加,这可能会变得非常慢。