如何在emacs中调试python程序?
我用 python-mode.el
我得到了参考
import pdb; pdb.set_trace();
Run Code Online (Sandbox Code Playgroud)
但不知道如何使用它.
我正在尝试将一个非常大的数据集(在ndarray中大约28GB的RAM)分配到theano共享变量中,使用borrow = True来避免复制内存.为此,我使用以下功能:
def load_dataset(path):
# Load dataset from memory
data_f = np.load(path+'train_f.npy')
data_t = np.load(path+'train_t.npy')
# Split into training and validation
return (
(
theano.shared(data_f[:-1000, :], borrow=True),
theano.shared(data_t[:-1000, :], borrow=True)
), (
theano.shared(data_f[-1000:, :], borrow=True),
theano.shared(data_t[-1000:, :], borrow=True)
)
)
Run Code Online (Sandbox Code Playgroud)
为了避免数据转换,在将阵列保存到磁盘之前,我已经将它们定义为正确的格式(之后填充它们并使用np.save()将它们转储到磁盘中):
data_f = np.ndarray((len(rows), 250*250*3), dtype=theano.config.floatX)
data_t = np.ndarray((len(rows), 1), dtype=theano.config.floatX)
Run Code Online (Sandbox Code Playgroud)
但是,似乎theano厌倦了复制内存,抛弃了以下错误:
分配25594500000字节的设备内存时出错(内存不足).驱动程序报告3775729664字节空闲,总计4294639616字节.
Theano配置为在GPU(GTX 970)上运行.
from sys import argv
script, first, second, third = argv
print("The script is called: ", script)
print("The first variable is: ", first)
print("The second variable is: ", second)
print("The third variable is: ", third)
Run Code Online (Sandbox Code Playgroud)
错误发生在script, first, second, third = argv.我想了解为什么我收到错误以及如何解决它.谢谢!
db.books.update({bookId:"123461"},{$set:{"bookPrice":"6.23"}})
Run Code Online (Sandbox Code Playgroud)
我收到错误:
update { q: { bookId: "123461" }, u: { $set: { bookPrice: "6.23" } }, multi: false, upsert: false } does not contain _id or shard key for pattern { _id: "hashed" }
Run Code Online (Sandbox Code Playgroud)
但是当我在下面使用时它起作用.
db.books.update({_id:ObjectId("54b88167498ec382221a82c2")},{$set: {"bookPrice":"6.23"}})
Run Code Online (Sandbox Code Playgroud)
为什么它不适用于bookId
在我的opencv3 Python3代码下方查找以匹配引发以下错误的对象:
类型错误:由名称 ('k') 和位置 (2) 给出的参数
这是代码:
import numpy as np
import cv2
import time
import distance
camera = cv2.VideoCapture(0)
sift = cv2.xfeatures2d.SIFT_create()
img = cv2.imread('/home/shar/bo.jpg')
imgTrainGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kpTrain = sift.detect(imgTrainGray,None)
kpTrain, desTrain = sift.compute(imgTrainGray, kpTrain)
FLANN_INDEX_KDTREE = 0
index_params = dict(algorithm = FLANN_INDEX_KDTREE, trees = 5)
search_params = dict(checks=50)
flann = cv2.FlannBasedMatcher(index_params,search_params)
matches = flann.knnMatch(kpTrain,desTrain,k=2)
Run Code Online (Sandbox Code Playgroud)
关于如何解决它的想法?
我正在测试Armadillo库,并编写了四个要构建的cpp文件。
我可以用一个命令来构建它们:
g++ chol.cpp conj_grad.cpp main.cpp special_mat.cpp -larmadillo -std=c++14 -o test
Run Code Online (Sandbox Code Playgroud)
但是,当我先编译单个文件并将它们链接时,我会遇到链接错误:
g++ -c -std=c++14 -g -O1 main.cpp -o main.o
g++ -c -std=c++14 -g -O1 chol.cpp -o chol.o
g++ -c -std=c++14 -g -O1 conj_grad.cpp -o conj_grad.o
g++ -c -std=c++14 -g -O1 special_mat.cpp -o special_mat.o
g++ -larmadillo main.o chol.o conj_grad.o special_mat.o -o test
Run Code Online (Sandbox Code Playgroud)
错误信息:
main.o: In function `main':
/home/me/doc/study/numerical_optimization/chap5/main.cpp:71: undefined reference to `TLS init function for arma::arma_rng_cxx11_instance'
main.o: In function `std::__detail::_Adaptor<std::mersenne_twister_engine<unsigned long, 64ul, 312ul, 156ul, 31ul, 13043109905998158313ul, 29ul, 6148914691236517205ul, 17ul, 8202884508482404352ul, …Run Code Online (Sandbox Code Playgroud) 我正在尝试开始学习python bottle框架,我已经安装了python 2.7.11,并且还安装了pip,我已经使用
pip install bottle
Collecting bottle
Using cached bottle-0.12.9.tar.gz
Installing collected packages: bottle
Running setup.py install for bottle ... done
Successfully installed bottle-0.12.9
Run Code Online (Sandbox Code Playgroud)
现在,我尝试从Bottle网站运行示例代码
from bottle import route, run, template
@route('/hello/<name>')
def index(name):
return template('<b>Hello {{name}}</b>!', name=name)
run(host='localhost', port=8080)
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时,它将引发以下错误
Traceback (most recent call last):
File "C:/Users/SID/Desktop/bottle.py", line 1, in <module>
from bottle import route, run, template
File "C:/Users/SID/Desktop\bottle.py", line 1, in <module>
from bottle import route, run, template
ImportError: cannot import name route
Run Code Online (Sandbox Code Playgroud)
我不知道出了什么问题可以有人指导我,这是代码的错误吗?还是瓶装?
注意:我在运行程序时尝试过python 3.4.3仍然仍然面临相同的错误,并且我在虚拟框中使用Windows 8.1
我的.csv数据如下:
June 8, 2009 Monday
June 8, 2009 Monday
June 6, 2009 Saturday
June 6, 2009 Saturday Correction Appended
June 6, 2009 Saturday
June 6, 2009 Saturday
June 6, 2009 Saturday
etc...
Run Code Online (Sandbox Code Playgroud)
数据跨越10年.我需要将月份和年份分开(并且不关心日期和日期).
单个月我有下一行代码:
for row in reader:
date = row[1]
month = date.partition(' ')[0]
print month
Run Code Online (Sandbox Code Playgroud)
但是我无法弄清楚如何从字符串中提取数字年份?我必须使用正则表达式吗?
我现在正在学习如何使用std :: find和自定义比较器.
但是,通过在线指导,我面临编译器错误.
链接到我的代码.
以下是我的代码:
#include <iostream>
#include <algorithm>
#include <pair.h>
#include <vector>
using namespace std;
int main()
{
struct comp
{
comp(const int& input) : _input(input) {}
bool operator()(const pair<int, int>& iPair)
{
return (iPair.first == _input);
}
int _input;
};
pair<int, int> pair1(1,3);
pair<int, int> pair2(2,4);
vector<pair<int, int> > vec;
vec.push_back(pair1);
vec.push_back(pair2);
vector<pair<int,int> >::iterator it = find(vec.begin(), vec.end(), comp(1));
if(it != vec.end())
{
cout << it->second << endl;
}
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误如下:
In function …Run Code Online (Sandbox Code Playgroud)