小编maj*_*r4x的帖子

`libusb_attach_kernel_driver`无效

我有一个问题是干净地关闭我使用的Linux应用程序libusb(内核不回收接口):

int rc;

rc = libusb_reset_device(handle_);
if (rc < 0) {
    cerr << "Error resetting the device: " << libusb_error_name(rc);
}

for (int ifnum = 0; ifnum < 2; ifnum++) {
    rc = libusb_release_interface(handle_, ifnum);
    if (rc < 0) {
        cerr << "Error releasing interface: " << libusb_error_name(rc);
    }
    if (libusb_kernel_driver_active(handle_, ifnum)) {
        cerr << "Reattaching CDC ACM kernel driver.";
        rc = libusb_attach_kernel_driver(handle_, ifnum);
        if (rc < 0) {
            cerr << "Error reattaching CDC ACM kernel driver: " …
Run Code Online (Sandbox Code Playgroud)

c++ linux usb libusb

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

Pandas DataFrame中的值的持续时间

我有以下DataFrame:

            f_1    f_2    f_3
00:00:00  False  False  False
00:05:22   True  False  False
00:06:40   True  False  False
00:06:41  False  False  False
00:06:42  False  False  False
00:06:43  False  False  False
00:06:44  False  False  False
00:06:46  False  False  False
00:06:58  False  False  False
Run Code Online (Sandbox Code Playgroud)

我想计算一个系列是真的总持续时间.在这个例子中,唯一成为True一段时间的系列是f_1.目前,我使用以下代码:

result = pandas.Timedelta(0)

for _, series in falsePositives.iteritems():
    previousTime = None
    previousValue = None
    for currentTime, currentValue in series.iteritems():
        if previousValue:
            result += (currentTime - previousTime)
        previousTime = currentTime
        previousValue = currentValue

print result.total_seconds()
Run Code Online (Sandbox Code Playgroud)

有更好的解决方案吗?我估计在Pandas中已经存在一种方法,它正在做这个或类似的事情.

python pandas

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

标签 统计

c++ ×1

libusb ×1

linux ×1

pandas ×1

python ×1

usb ×1