小编Mar*_*l B的帖子

如何将数据导入mongoDB

我正在尝试以 JSON 格式导入大型数据文件。我正在使用

mongoimport --db verbs --collection de --file "/Users/marcelbraasch/Downloads/de.json"

导入数据。这是正在经历的,但是,我收到以下异常:

失败:(未授权)未授权动词执行命令 { 插入:“de”,有序:false,writeConcern:{ w:“多数”},$db:“动词”}

我已经尝试过这样的组合

mongoimport -h localhost:27017 -u 'user' -p 'password' --db verbs --collection de --file "/Users/myname/Downloads/de.json"

但没有一个奏效。如果此信息很重要,我的 mongo 实例正在 docker 容器中运行。我需要做什么?

mongodb mongoimport

7
推荐指数
1
解决办法
6817
查看次数

如何高效创建子字符串

给定一个字符串(通常是一个句子),我想提取 lengths 的所有子字符串3, 4, 5, 6。如何仅使用 Python 的标准库有效地实现这一目标?这是我的方法,我正在寻找一种更快的方法。对我来说,这三个外循环似乎都是不可避免的,但也许有一个低级优化的解决方案itertools

import time

def naive(test_sentence, start, end):
    grams = []
    for word in test_sentence:
        for size in range(start, end):
            for i in range(len(word)):
                k = word[i:i+size]
                if len(k)==size:
                    grams.append(k)
    return grams

n = 10**6
start, end = 3, 7
test_sentence = "Hi this is a wonderful test sentence".split(" ")

start_time = time.time()
for _ in range(n):
    naive(test_sentence, start, end)
end_time = time.time()

print(f"{end-start} seconds for naive approach") …
Run Code Online (Sandbox Code Playgroud)

python performance

5
推荐指数
1
解决办法
426
查看次数

使用列表解析将元组列表转换为其元素列表

我目前正在为10月份的考试而学习,并且遇到了一个问题,我似乎无法找到一个好的解决方案.

我想读一下这样的整数元组列表:[(1,2),(3,4),(5,6),..]并希望列表理解返回[1,2,3, 4,5,6,...]

以下工作正常,但我希望它在一个列表理解中.

func :: [(Integer, Integer)] -> [Integer]
func xs = concat [ [x,y] | (x,y) <- xs ]
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

haskell list-comprehension list

3
推荐指数
1
解决办法
75
查看次数

LSTM 错误:AttributeError:“tuple”对象没有属性“dim”

我有以下代码:

import torch
import torch.nn as nn

model = nn.Sequential(
          nn.LSTM(300, 300),
          nn.Linear(300, 100),
          nn.ReLU(),
          nn.Linear(300, 7),
          )

s = torch.ones(1, 50, 300)
a = model(s)
Run Code Online (Sandbox Code Playgroud)

我得到:

My-MBP:Desktop myname$ python3 testmodel.py 
Traceback (most recent call last):
  File "testmodel.py", line 12, in <module>
    a = model(s)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torch/nn/modules/container.py", line 117, in forward
    input = module(input)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torch/nn/modules/module.py", line 727, in _call_impl
    result = self.forward(*input, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/torch/nn/modules/linear.py", line 93, in forward …
Run Code Online (Sandbox Code Playgroud)

python lstm pytorch

2
推荐指数
1
解决办法
4277
查看次数