是否可以使用Mongo查询在数组中的对象的字段中具有特定值的条目.
例如,假设我想找到field1有一个对象数组的所有对象,其中一个对象的字段为'one',值为1.此查询应从我的集合中返回以下对象:
{_id: 0000, field1: [{one: 1, two: 2}, {one: 'uno', two: 'dos'}]}
Run Code Online (Sandbox Code Playgroud) 因此,当登录无法验证时,我目前正在使用res.send(401).但是我想发送一段文本或html以及错误代码.
我试过这个:
res.write('string');
res.send(401);
Run Code Online (Sandbox Code Playgroud)
但是扔了一个错误,我的服务器无法启动.
我的虚拟数据集中有12个长度为200的向量,每个向量代表一个样本。假设x_train是一个带有shape的数组(12, 200)。
当我做:
model = Sequential()
model.add(Conv1D(2, 4, input_shape=(1, 200)))
Run Code Online (Sandbox Code Playgroud)
我得到错误:
ValueError: Error when checking model input: expected conv1d_1_input to have 3 dimensions, but got array with shape (12, 200)
Run Code Online (Sandbox Code Playgroud)
如何正确调整输入数组的形状?
这是我更新的脚本:
data = np.loadtxt('temp/data.csv', delimiter=' ')
trainData = []
testData = []
trainlabels = []
testlabels = []
with open('temp/trainlabels', 'r') as f:
trainLabelFile = list(csv.reader(f))
with open('temp/testlabels', 'r') as f:
testLabelFile = list(csv.reader(f))
for i in range(2):
for idx in trainLabelFile[i]:
trainData.append(data[int(idx)])
# append …Run Code Online (Sandbox Code Playgroud) 我正在处理一个包含 640 万个样本和 500 个维度的数据集,我正在尝试将其分组为 200 个集群。我的内存限制为 90GB,当我尝试从 sklearn.cluster 运行 MiniBatchKmeans 时,操作系统会因为使用过多内存而终止进程。
这是代码:
data = np.loadtxt('temp/data.csv', delimiter=',')
labels = np.genfromtxt('temp/labels', delimiter=',')
kmeans = cluster.MiniBatchKMeans(n_clusters=numClusters, random_state=0).fit(data)
predict = kmeans.predict(data)
Tdata = kmeans.transform(data)
Run Code Online (Sandbox Code Playgroud)
它不会通过聚类。
我正在构建一个具有类似reddit功能的网站.我希望用户提交的内容能够获得自己的页面.每个提交都分配了一个5个字符的ID,我想要在该页面的URL中.
我在路由器文件中有这个函数,它呈现一个名为titles的页面:
exports.titles = function(req, res){
i = 0
read(function(post){
url = post[i].URL;
res.render('titles', {title: post[i].title, url: post[i].URL});
});
};
Run Code Online (Sandbox Code Playgroud)
它在app.js中由此语句提供:
app.get('/titles', home.titles); //home.js is the router file
Run Code Online (Sandbox Code Playgroud)
标题页面包含文本post.title和URL post.URL的链接.当用户点击链接(例如domain.com/12345)时,他们应该被带到内容post.body的名为content的页面.
我如何a)将URL传递回我的app.js文件以包含在app.get中,b)在此路由器文件中包含app.get函数,或c)以任何其他方式解决此问题?
编辑:我确实有一个对象'titles'是一个mongodb集合,但它在一个不同的模块中.没理由我不能把它添加到路由器.
编辑:我尝试将此添加到app.js以查看它是否可行:
app.get('/:id', function(req, res){
return titles.findOne({ id: req.params.id }, function (err, post) {
if (err) throw(err);
return res.render('content', {title: post.title, content: post.body});
});
});
Run Code Online (Sandbox Code Playgroud)
编辑:我得到了它的工作.我所做的只是格式化标题,使其看起来像domain.com/titles/12345并更改app.get('/:id',更改为app.get('/ titles /:id,...
我搜索并发现很多类似的问题,会话变量设置为undefined,但我找到的答案似乎都没有适用.
我的路由器文件中有这个功能:
exports.loginHandler = function(req, res){
username = req.body.username;
password = req.body.password;
readAccount(username, function(acct){
if (acct.password = password){
req.session.username = username;
console.log(username+' logged in'+' pass: '+acct.password);
};
});
res.redirect('/');
};
Run Code Online (Sandbox Code Playgroud)
console.log执行得很好,username和acct.password都有适当的值.但是,req.session.username最终被设置为undefined.
这是readAccount函数:
readAccount = function(user, callback){
AM.login(user, function(acct){
callback(acct);
});
};
Run Code Online (Sandbox Code Playgroud)
这是AM.login:
exports.login = function(user, callback){
accounts.findOne({username: user}, function(err, result){
if (err) throw err;
callback(result);
})
}
Run Code Online (Sandbox Code Playgroud)
我猜测会话变量不能在条件下设置,因为这种类型的错误似乎并不常见.