我试图使用以下代码列出S3容器中的项目.
import boto.s3
from boto.s3.connection import OrdinaryCallingFormat
conn = boto.connect_s3(calling_format=OrdinaryCallingFormat())
mybucket = conn.get_bucket('Container001')
for key in mybucket.list():
print key.name.encode('utf-8')
Run Code Online (Sandbox Code Playgroud)
然后我收到以下错误.
Traceback (most recent call last):
File "test.py", line 5, in <module>
mybucket = conn.get_bucket('Container001')
File "/usr/lib/python2.7/dist-packages/boto/s3/connection.py", line 370, in get_bucket
bucket.get_all_keys(headers, maxkeys=0)
File "/usr/lib/python2.7/dist-packages/boto/s3/bucket.py", line 358, in get_all_keys
'', headers, **params)
File "/usr/lib/python2.7/dist-packages/boto/s3/bucket.py", line 325, in _get_all
response.status, response.reason, body)
boto.exception.S3ResponseError: S3ResponseError: 301 Moved Permanently
<?xml version="1.0" encoding="UTF-8"?>
PermanentRedirectThe bucket you are attempting to access must be addressed using the …Run Code Online (Sandbox Code Playgroud) 我想在scikit中使用RBM.我可以像许多其他分类器一样定义和训练RBM.
from sklearn.neural_network import BernoulliRBM
clf = BernoulliRBM(random_state=0, verbose=True)
clf.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
但我似乎无法找到一个让我成为预测的功能.我正在寻找scikit中以下之一的等效物.
y_score = clf.decision_function(X_test)
y_score = clf.predict(X_test)
Run Code Online (Sandbox Code Playgroud)
BernoulliRBM中没有这两种功能.
我试图了解池和队列如何在Python中工作,并且以下示例未按预期工作。我希望程序结束,但是由于第二个队列没有清空,它陷入了无限循环。
import multiprocessing
import os
import time
inq = multiprocessing.Queue()
outq = multiprocessing.Queue()
def worker_main(q1, q2):
while True:
i = q1.get(True)
time.sleep(.1)
q2.put(i*2)
def worker2(q):
print q.get(True)
p1 = multiprocessing.Pool(3, worker_main,(inq, outq,))
p2 = multiprocessing.Pool(2, worker2,(outq,))
for i in range(50):
inq.put(i)
while inq.qsize()>0 or outq.qsize()>0:
print 'q1 size', inq.qsize(), 'q2 size', outq.qsize()
time.sleep(.1)
Run Code Online (Sandbox Code Playgroud)
输出显示第二个队列(outq)为.get一次,仅此而已。
输出:
Run Code Online (Sandbox Code Playgroud)q1 size 49 q2 size 0 q1 size 47 q2 size 0 2 4 q1 size 44 q2 size 1 q1 size 41 q2 size …