在列表中显示mongo中的相应字段(display corresponding fields in mongo in a list)
这是我存储的数据:
{ "_id" : ObjectId("57080a7b01351177a4113f63"), "title" : "Data Scientist", "url" : "https://www.Pinterest.com/jobs/732?t=nu6xow", "timestamp" : "2016-04-08 19:46:03", "company" : "Pinterest", "state" : " CA", "todays_date" : "04/08/2016", "city_name" : "San+Francisco", "location" : "San Francisco, CA", "team" : "T0BT323QS", "search_word" : "Data+scientist"} { "_id" : ObjectId("57080a7b01351177a4113f64"), "title" : "Director of Analytics / Data Mining", "url" : "http://www.Pinterest.com/careers-position-data-mining-leader", "timestamp" : "2016-04-08 19:46:03", "company" : "Pinterest", "state" : " CA", "todays_date" : "04/08/2016", "city_name" : "San+Francisco", "location" : "Silicon Valley, CA", "team" : "T0BT323QS", "search_word" : "Data+scientist"} { "_id" : ObjectId("57080a7d01351177a4113f65"), "title" : "Senior Real World Data Scientist", "url" : "http://www.Pinterest.com/careers/detail/00443369/Senior-Real-World-Data-Scientist?src=JB-12568", "timestamp" : "2016-04-08 19:46:05", "company" : "Pinterest", "state" : " CA", "todays_date" : "04/08/2016", "city_name" : "San+Francisco", "location" : "South San Francisco, CA", "team" : "T0BT323QS", "search_word" : "Data+scientist"}
这是我的查询:
db.Books.aggregate([{$match:{"timestamp":{ $gte: "2016-04-08 19:46:03", $lt: "2016-04-08 19:46:06"}}} ,{ "$group": { "_id": "$company", "count": { "$sum": 1 }, "urls": { "$addToSet": "$url" } }}, { "$sort": { "count": -1 } }, { "$limit": 10 }, { "$project": { "count": 1, "urls": { "$slice": ["$urls",0, 3] } }} ])
这是输出:
{ "_id" : "Pinterest", "urls" : [ "https://www.Pinterest.com/jobs/732?t=nu6xow", "http://www.Pinterest.com/careers-position-data-mining-leader", "http://www.Pinterest.com/careers/detail/00443369/Senior-Real-World-Data-Scientist?src=JB-12568" ] }
但是,与“url”一起,我希望它显示相应的“标题”和“位置”字段。 像这样的东西:
{ "_id" : "Pinterest", "urls" : [ [ "https://www.Pinterest.com/jobs/732?t=nu6xow", "Data Scientist","San Francisco, CA" ],[ "http://www.Pinterest.com/careers-position-data-mining-leader", "Director of Analytics / Data Mining","Silicon Valley, CA" ],[ "http://www.Pinterest.com/careers/detail/00443369/Senior-Real-World-Data-Scientist?src=JB-12568", "Senior Real World Data Scientist", "South San Francisco, CA" ] ]}
This is my stored data:
{ "_id" : ObjectId("57080a7b01351177a4113f63"), "title" : "Data Scientist", "url" : "https://www.Pinterest.com/jobs/732?t=nu6xow", "timestamp" : "2016-04-08 19:46:03", "company" : "Pinterest", "state" : " CA", "todays_date" : "04/08/2016", "city_name" : "San+Francisco", "location" : "San Francisco, CA", "team" : "T0BT323QS", "search_word" : "Data+scientist"} { "_id" : ObjectId("57080a7b01351177a4113f64"), "title" : "Director of Analytics / Data Mining", "url" : "http://www.Pinterest.com/careers-position-data-mining-leader", "timestamp" : "2016-04-08 19:46:03", "company" : "Pinterest", "state" : " CA", "todays_date" : "04/08/2016", "city_name" : "San+Francisco", "location" : "Silicon Valley, CA", "team" : "T0BT323QS", "search_word" : "Data+scientist"} { "_id" : ObjectId("57080a7d01351177a4113f65"), "title" : "Senior Real World Data Scientist", "url" : "http://www.Pinterest.com/careers/detail/00443369/Senior-Real-World-Data-Scientist?src=JB-12568", "timestamp" : "2016-04-08 19:46:05", "company" : "Pinterest", "state" : " CA", "todays_date" : "04/08/2016", "city_name" : "San+Francisco", "location" : "South San Francisco, CA", "team" : "T0BT323QS", "search_word" : "Data+scientist"}
This is my query:
db.Books.aggregate([{$match:{"timestamp":{ $gte: "2016-04-08 19:46:03", $lt: "2016-04-08 19:46:06"}}} ,{ "$group": { "_id": "$company", "count": { "$sum": 1 }, "urls": { "$addToSet": "$url" } }}, { "$sort": { "count": -1 } }, { "$limit": 10 }, { "$project": { "count": 1, "urls": { "$slice": ["$urls",0, 3] } }} ])
This is the output:
{ "_id" : "Pinterest", "urls" : [ "https://www.Pinterest.com/jobs/732?t=nu6xow", "http://www.Pinterest.com/careers-position-data-mining-leader", "http://www.Pinterest.com/careers/detail/00443369/Senior-Real-World-Data-Scientist?src=JB-12568" ] }
However, alongwith "url" I want it to display corresponding "title" and "location" field. Something like this:
{ "_id" : "Pinterest", "urls" : [ [ "https://www.Pinterest.com/jobs/732?t=nu6xow", "Data Scientist","San Francisco, CA" ],[ "http://www.Pinterest.com/careers-position-data-mining-leader", "Director of Analytics / Data Mining","Silicon Valley, CA" ],[ "http://www.Pinterest.com/careers/detail/00443369/Senior-Real-World-Data-Scientist?src=JB-12568", "Senior Real World Data Scientist", "South San Francisco, CA" ] ]}
原文:https://stackoverflow.com/questions/36753436
最满意答案
我不确定你是否可以,但我认为你可能不需要。 您已经拥有以下工具:
tf.contrib.framework.is_tensor
将为tf.contrib.framework.is_tensor
返回True
tf.executing_eagerly
返回True
如果你是,那么急切地执行。我相信他们应该覆盖99%的需求 - 如果漏掉了这个百分比,我会很好奇听到你的问题。
I am not sure if you can, but I think you probably don't need to. You already have the following tools:
tf.contrib.framework.is_tensor
that will returnTrue
for anEagerTensor
tf.executing_eagerly
that returnsTrue
if you are, well, executing eagerly.I believe they should cover 99% of your needs -- and I would be curious to hear about your problem if it falls in that percentage left out.
相关问答
更多-
因为seq2seq已被移至tf.contrib.legacy_seq2seq 。 您应该将此行更改为: outputs, final_state = tf.contrib.legacy_seq2seq.rnn_decoder(inputs, istate, cell, loop_function=None, scope='rnnlm') Because seq2seq has been moved to tf.contrib.legacy_seq2seq. You should change this l ...
-
只有在对所有数据集运行“推理”后,才能使用sklearn的confusion_matrix。 这意味着,如果要修改eval_only函数,则应将所有分数累积到某个线程安全容器(列表)中。 然后在所有线程停止后(第113行),您可以运行单一混淆矩阵计算。 另外,如果你想在图表中做到这一点,TensorFlow最近得到了confusion_matrix你可以试试。 也就是说,它只适用于批处理,因此您需要增加批处理以获得任何类型的解析或编写自定义聚合器。 You can utilize sklearn's con ...
-
您可以从Optimizer类实现自己的优化Optimizer 。 您必须至少实现方法_apply_dense或_apply_sparse 。 使用纯已经可用的tensorflow操作完整实现adamax优化器。 class AdamaxOptimizer(optimizer.Optimizer): .. you can create slot variables implementing slot fucntion def _create_slots(self, var_list): ...
-
我设法解决了这个问题。 在这个例子中我忘了添加一个参数来优化。 import tensorflow as tf import numpy as np # Test data x_dat = np.arange(1, 13).reshape(4, 3).astype(np.float32) y_dat = np.arange(1, 9).reshape(4, 2).astype(np.float32) # Test data x = tf.placeholder(tf.float32, [None, 3] ...
-
Eclipse的TensorFlow(TensorFlow with Eclipse)[2022-08-07]
这听起来像是你的Python环境遇到了问题。 处理这个问题的最简单方法是遵循以下步骤: 按照此处的说明将TensorFlow安装到virtualenv中。 这样就避免了获取root权限的需要,并且可以更轻松地尝试不同版本的TensorFlow。 (它也避免了与其他系统安装的不同库的版本冲突。) 按照本指南中的第5步开始,设置PyDev以使用新的virtualenv。 这涉及到建立一个新的“解释器”,它的库将成为virtualenv中的一组库。 您可能需要重新创建您的Eclipse项目才能使用此解释器。 It ... -
在初始化所有变量之前,函数foo()根本没有被调用。 所以它无法初始化foo()中的变量。 我们需要在运行会话之前调用该函数。 import tensorflow as tf def foo(): x=tf.Variable(tf.zeros([1])) y=tf.ones([1]) return x+y with tf.Session() as sess: result=foo() init=tf.global_variables_initializer() ...
-
我不确定你是否可以,但我认为你可能不需要。 您已经拥有以下工具: tf.contrib.framework.is_tensor将为tf.contrib.framework.is_tensor返回True tf.executing_eagerly返回True如果你是,那么急切地执行。 我相信他们应该覆盖99%的需求 - 如果漏掉了这个百分比,我会很好奇听到你的问题。 I am not sure if you can, but I think you probably don't need to. You al ...
-
在TensorFlow中编写分段函数/如果在TensorFlow中(Writing piece-wise functions in TensorFlow / if then in TensorFlow)[2022-12-11]
你应该看看tf.select 。 举个例子,你可以这样做: condition = tf.greater(x, 0) res = tf.select(condition, tf.square(x), x + 5) You should take a look at tf.where. For your example, you could do: condition = tf.greater(x, 0) res = tf.where(condition, tf.square(x), x + 5) EDI ... -
my_model不会在您的代码中调用。 它是一个由Estimator调用的具有2个参数的回调函数:特征和标签。 对于fit()函数,它们实际上是x_train和y_train 。 正如文档所说, “模型函数,具有特征和目标张量或张量,并返回预测和损失张量,例如”(特征,目标) - >(预测,损失)“ 您可以在Estimator的源代码中看到1125行中调用了model_fn: model_fn_results = self._model_fn(features, labels, **kwargs) my_ ...
-
我有同样的问题,运行以下命令解决了我的问题: ./configure 我使用了所有默认配置。 请查看此问题以获取更多信息。 I had the same issue, running the following command solved the problem for me: ./configure I used all the default configurations. Check this issue for more info.