小编phi*_*hag的帖子

ValueError("color kwarg每个数据集必须有一种颜色")?

我只是将数据保存到文件中并将其读出然后绘制直方图.然而,虽然我实际上没有改变原始代码,但看起来这个错误.谁能告诉我什么是错的?非常感谢.

这是hist()的代码

f_120 = plt.figure(1)
plt.hist(tfirst_list, bins=6000000, normed = True, histtype ="step", cumulative = True, color = 'g',label = 'first answer')
plt.axvline(x = 30, ymin = 0, ymax = 1, color = 'r', linestyle = '--', label = '30 min')
plt.axvline(x = 60, ymin = 0, ymax = 1, color = 'c', linestyle = '--', label = '1 hour')
plt.legend()

plt.ylabel('Percentage of answered questions')
plt.xlabel('Minutes elapsed after questions are posted')
plt.title('Cumulative histogram: time elapsed \n before questions receive answer (first …
Run Code Online (Sandbox Code Playgroud)

python matplotlib

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

客户端应用程序在C#中在本地网络上查找服务器的最佳方式是什么?

客户端使用GenuineChannels连接到服务器(我们正在考虑切换到DotNetRemoting).我的意思是找到要连接的服务器的IP和端口号.

看起来像蛮力的方法是尝试网络上的每个IP尝试活动端口(甚至不确定是否可能)但必须有更好的方法.

c# remoting client-server service-discovery

12
推荐指数
3
解决办法
5227
查看次数

在C中,访问我的数组索引更快或通过指针访问更快?

在C中,访问数组索引更快或通过指针访问更快?我的意思是更快,哪一个会占用更少的时钟周期.该数组不是常量数组.

c optimization assembly

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

赶快承诺拒绝

如何在以后检索承诺的结果?在测试中,我在发送进一步请求之前检索电子邮件:

const email = await get_email();
assert.equal(email.subject, 'foobar');
await send_request1();
await send_request2();
Run Code Online (Sandbox Code Playgroud)

如何在慢速邮件检索过程中发送请求?

起初,我考虑过稍后等待电子邮件:

// This code is wrong - do not copy!
const email_promise = get_email();
await send_request1();
await send_request2();
const email = await email_promise;
assert.equal(email.subject, 'foobar');
Run Code Online (Sandbox Code Playgroud)

如果get_email()成功,这可以工作,但如果get_email()在相应的之前失败则失败await,并且完全合理UnhandledPromiseRejectionWarning.

当然,我可以使用Promise.all,像这样:

await Promise.all([
    async () => {
        const email = await get_email();
        assert.equal(email.subject, 'foobar');
    },
    async () => {
        await send_request1();
        await send_request2();
    },
]);
Run Code Online (Sandbox Code Playgroud)

然而,它使代码更难阅读(它看起来更像是基于回调的编程),尤其是在以后的请求实际上依赖于电子邮件,或者有一些嵌套回事.是否可以在以后存储承诺的结果/例外await

如果需要,这里有一个带有模拟 …

javascript node.js promise async-await es6-promise

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

一次查询多个值

在SQL中,我可以得到一组这样的行:

SELECT * FROM table WHERE id in (2,3,5,7,11);
Run Code Online (Sandbox Code Playgroud)

等效的sqlalchemy查询看起来如何?cls.id in [2,3,5,7,11]评估为False,所以这段代码:

q = meta.Session.query(cls)
q = q.filter(cls.id in [2,3,5,7,11])
return q.all()
Run Code Online (Sandbox Code Playgroud)

失败,但有例外:

  File "foo.py", line 1234, in findall_by_ids
    q = q.filter(cls.id in [2,3,5,7,11])
  File "<string>", line 1, in <lambda>
  File "/eggs/sqlalchemy/orm/query.py", line 50, in generate
    fn(self, *args[1:], **kw)
  File "/eggs/sqlalchemy/orm/query.py", line 1177, in filter
    "filter() argument must be of type "
ArgumentError: filter() argument must be of type sqlalchemy.sql.ClauseElement
               or string
Run Code Online (Sandbox Code Playgroud)

sqlalchemy

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

捕获退格键事件

我很难在javascript/jQuery中将退格键捕获为键盘事件.在Firefox,Safari,Opera,Chrome和iPhone/iPad上,我在文本输入框上捕获了一个keyup事件,如下所示:

$(id_input).keyup(function(event) {
   that.GetHints($(this).val().trim(), event, fieldName);
});
Run Code Online (Sandbox Code Playgroud)

此事件捕获用户击键,然后将它们发送到函数以发出ajax查找调用.

当用户希望对他/她已输入的角色进行退格时,我的问题就来了.在除了我的Droid手机之外我可以访问的所有浏览器中,当我按退格键时,此keyup事件捕获$(this).val().trim()返回的值并将其发送到函数进程GetHints.但是,在Droid上,在用户对$(this)中的每个字符进行退格操作之前,此keyup和等效的keydown事件都不会触发.

因此,例如,如果我输入"cu"然后退回"u",在输入字段中只留下"c",在除Droid之外的所有浏览器中,keyup事件将触发并调用函数GetHints("c", event, fieldName).在Droid上,keyup事件永远不会发生.

我错过了什么?如何/为什么我的Droid上的软键盘或硬键盘上的退格键不能按预期运行?我该如何解决这个问题?

javascript jquery android

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

Libusb undefined引用

我正在尝试在我的操作系统上设置libusb API.我在libusb.org上下载了libusb api.我遵循标准安装程序:

cd into directory
./configure
make
make check //without errors
make install
Run Code Online (Sandbox Code Playgroud)

然后我启动了Eclipse C/C++并从互联网上的教程中复制了一些代码.但是在尝试构建它时,我得到了以下输出:

main.cpp:(.text+0x19): undefined reference to `libusb_init'
main.cpp:(.text+0x76): undefined reference to `libusb_set_debug'
main.cpp:(.text+0x8a): undefined reference to `libusb_get_device_list'
main.cpp:(.text+0x136): undefined reference to `libusb_free_device_list'
main.cpp:(.text+0x142): undefined reference to `libusb_exit'
/tmp/ccOWJGwe.o: In function `printdev(libusb_device*)':
main.cpp:(.text+0x162): undefined reference to `libusb_get_device_descriptor'
main.cpp:(.text+0x28a): undefined reference to `libusb_get_config_descriptor'
main.cpp:(.text+0x4d4): undefined reference to `libusb_free_config_descriptor'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)

我在/ lib中有libusb.so,我在/ usr/local/include中有usb.h,在/ usr/local/lib中有.so和libusb.a的链接.

代码中的#include也是正确的.

我知道问题出现在链接器中但是我有点不能使它工作:)

我正在使用Fedora 15操作系统和gcc 4.6.0 20110603(Red Hat 4.6.0-10)版本编译器.

那么我该怎么办才能解决这些未定义的引用呢?非常感谢你的帮助:)

c++ linux linker libusb

9
推荐指数
2
解决办法
3万
查看次数

将websockets与标准http.Server集成

我有一个简单的Web服务器一样

var http = require('http'),
    url = require('url');
var server = http.createServer(function (req, res) {
  var uri = url.parse(req.url).pathname;
  if (uri == '/') {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.end('Hello World\n');
    return;
  }

  res.writeHead(404, {'Content-Type': 'text/plain'});
  res.end('File not found');
});
server.listen(0, '127.0.0.1');
Run Code Online (Sandbox Code Playgroud)

我现在想将一条路径(比方说/ws)连接到一个websocket,但不要修改服务器的其余部分.

但是,ws似乎要求我设置一个专用服务器(包括所有必需的服务器,如SSL终止,安全配置和端口分配).

如何终止/wswebsocket实现的路径?

websocket node.js

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

将通道的所有元素都消耗到切片中

如何从通道消耗的所有元素中构造切片(如Python的list那样)?我可以使用这个辅助函数:

func ToSlice(c chan int) []int {
    s := make([]int, 0)
    for i := range c {
        s = append(s, i)
    }
    return s
}
Run Code Online (Sandbox Code Playgroud)

但由于缺乏泛型,我不得不为每种类型写出来,不是吗?是否有内置函数来实现这一点?如果没有,我怎么能避免为我正在使用的每一种类型复制和粘贴上面的代码?

go channels

9
推荐指数
2
解决办法
5243
查看次数

subprocess python filenotfounderror:[winerror 2]

我一直在使用Jupyter Notebook 从kaggle学习主成分分析),但是当我运行这段代码时

     from subprocess import check_output
     print(check_output(["ls", "../input"]).decode("utf8"))
Run Code Online (Sandbox Code Playgroud)

我在下面收到了一个错误

FileNotFoundError Traceback (most recent call last)
<ipython-input-3-de0e39ca3ab8> in <module>()
      1 from subprocess import check_output
----> 2 print(check_output(["ls", "C:/Users/wanglei/Documents/input"]).decode("utf8"))

D:\Anaconda3\lib\subprocess.py in check_output(timeout, *popenargs, **kwargs)
    624 
    625     return run(*popenargs, stdout=PIPE, timeout=timeout, check=True,
--> 626                **kwargs).stdout
    627 
    628 

D:\Anaconda3\lib\subprocess.py in run(input, timeout, check, *popenargs, **kwargs)
    691         kwargs['stdin'] = PIPE
    692 
--> 693     with Popen(*popenargs, **kwargs) as process:
    694         try:
    695             stdout, stderr = process.communicate(input, timeout=timeout)

D:\Anaconda3\lib\subprocess.py in __init__(self, args, bufsize, …
Run Code Online (Sandbox Code Playgroud)

python subprocess python-3.x jupyter-notebook kaggle

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