小编tgy*_*tgy的帖子

django,pyenv,uwsgi - ModuleNotFoundError:没有名为'django'的模块

我有以下附庸配置/etc/uwsgi/vassals/gsd.ini:

[uwsgi]
plugins = python
env = DJANGO_SETTINGS_MODULE=%n.settings
virtualenv = /home/toogy/.pyenv/versions/%n
chdir = /home/webapps/%n
module = %n.wsgi:application
master = true
vacuum = true
pidfile = /tmp/uwsgi-%n.pid
socket = /tmp/uwsgi-%n.sock
daemonize = /var/log/uwsgi/%n.log
chmod-socket = 666
uid = toogy
gid = toogy
Run Code Online (Sandbox Code Playgroud)

这是我得到的uwsgi日志

Tue Feb  7 10:49:12 2017 - received message 1 from emperor
...gracefully killing workers...
Gracefully killing worker 1 (pid: 31406)...
worker 1 buried after 1 seconds
binary reloading uWSGI...
chdir() to /etc/uwsgi/vassals
closing all non-uwsgi socket …
Run Code Online (Sandbox Code Playgroud)

python django uwsgi pyenv

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

比较用std :: bind创建的std :: function

这是一个玩具的例子

#include <iostream>
#include <functional>

struct Obj
{
  int x;

  int foo()
  {
    return 42;
  }
};

int main()
{
  Obj a, b;
  std::function<int()> f1 = std::bind(&Obj::foo, &a);
  std::function<int()> f2 = std::bind(&Obj::foo, &b);
  std::function<int()> f3 = std::bind(&Obj::foo, &a);
  std::function<int()> f4 = std::bind(&Obj::foo, &b);
}
Run Code Online (Sandbox Code Playgroud)

我如何验证,f1 == f3并且f2 == f4,==比较器在这里,这意味着两个std::function对象对应于同一对象的相同方法?

c++ stdbind c++11 std-function

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

numpy:与非零相反(获取零元素的索引)

numpy.nonzero对于获取非零元素的索引很有用。它返回一个数组元组,每个数组都包含特定轴的非零元素的索引。

除了零元素之外是否有等价的?

这意味着对于给定的 numpy 数组

x = [[1, 2, 0],
     [8, 0, 2],
     [0, 0, 1]]
Run Code Online (Sandbox Code Playgroud)

我可以得到如下索引

ax0_zero_idxs, ax1_zero_idxs = numpy.zero(x)
Run Code Online (Sandbox Code Playgroud)

在哪里

ax0_zero_idxs = [0, 1, 2, 2]
ax1_zero_idxs = [2, 1, 0, 1]
Run Code Online (Sandbox Code Playgroud)

python numpy

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

C++ 11初始化对象的指针列表

编辑:这个结构是真正糟糕的设计,不要使用它!

是否可以在C++ 11中初始化一个指向对象的指针列表(同时初始化所有内容)?

例如,假设我想要创建my_list哪种类型:

list<pair<string, map<string, string> *> *>.

我想用原始值初始化它.

list<pair<string, map<string, string> *> *> my_list = { ??? }

???:创建新的指针到新的对原始字符串和新指针的原始字符串的地图.

(为什么我需要这样做:这个数据结构存储从文件中读取的配置,但如果找不到该文件,我的代码中需要一个默认值)

c++ pointers initialization c++11

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

值类型为reference_wrapper时的unordered_map值赋值

我正在试验std::reference_wrapper.我不明白为什么以下内容适用于a std::vector但不适用于std::unordered_map:

#include <functional>
#include <vector>
#include <unordered_map>

using namespace std;

int main()
{
  vector<vector<long>> x;

  vector<reference_wrapper<vector<vector<long>>>> y;
  y.push_back(ref(x)); // OK

  unordered_map<string, reference_wrapper<vector<vector<long>>>> m;
  m["lol"] = ref(x); // NOT OK
}
Run Code Online (Sandbox Code Playgroud)

这是我得到的编译错误

/usr/include/c++/7.2.0/tuple:1652:70: error: no matching function for call to ‘std::
reference_wrapper<std::vector<std::vector<long int> > >::reference_wrapper()’       
         second(std::forward<_Args2>(std::get<_Indexes2>(__tuple2))...)
                                                                      ^
In file included from /usr/include/c++/7.2.0/bits/std_function.h:44:0,              
                 from /usr/include/c++/7.2.0/functional:58,                         
                 from test.cpp:1:         
/usr/include/c++/7.2.0/bits/refwrap.h:325:7: note: candidate: constexpr std::referen
ce_wrapper<_Tp>::reference_wrapper(const std::reference_wrapper<_Tp>&) [with _Tp = s
td::vector<std::vector<long int> >]       
       reference_wrapper(const reference_wrapper&) = default;                       
       ^~~~~~~~~~~~~~~~~ …
Run Code Online (Sandbox Code Playgroud)

c++ reference c++11 reference-wrapper

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

(opencv)imread with CV_LOAD_IMAGE_GRAYSCALE产生一个4通道Mat

以下代码将文件中的图像读入cv::Mat对象.

#include <string>

#include <opencv2/opencv.hpp>

cv::Mat load_image(std::string img_path)
{
  cv::Mat img = cv::imread(img_path, CV_LOAD_IMAGE_GRAYSCALE);
  cv::Scalar intensity = img.at<uchar>(0, 0);
  std::cout << intensity << std::endl;
  return img;
}
Run Code Online (Sandbox Code Playgroud)

我希望cv::Mat只有一个通道(即图像的强度),但它有4个.

$ ./test_load_image
[164, 0, 0, 0]
Run Code Online (Sandbox Code Playgroud)

我也试过转换图像

cv::Mat gray(img.size(), CV_8UC1);
img.convertTo(gray, CV_8UC1);
Run Code Online (Sandbox Code Playgroud)

gray矩阵也是一个4通道.

我想知道是否可以有一个频道cv::Mat.直观地说,这是我在处理灰度(因此,单通道)图像时所期望的.

opencv image-processing

0
推荐指数
1
解决办法
431
查看次数