小编koe*_*egl的帖子

scipy没有属性信号

我有一个从另一个文件导入函数的文件,如下所示。

文件1.py:

# import scipy.signal
import file2

file2.foo()

Run Code Online (Sandbox Code Playgroud)

文件2.py:

import scipy


def foo():
    scipy.signal.butter(2, 0.01, 'lowpass', analog=False)

Run Code Online (Sandbox Code Playgroud)

当我运行 file1.py 时,出现以下错误:

文件“file2.py”,第 5 行,在 foo scipy.signal.butter(2, 0.01, 'lowpass', Analog=False) AttributeError: 模块 'scipy' 没有属性 'signal'

但是,当我取消file1.py ( import scipy.signal) 中的第 1 行注释时,错误消失了。为什么会发生这种情况?

python scipy

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

为什么在带参数包的递归中需要 constexpr

我有一个简单的递归函数来打印参数包中的每个参数

#include <iostream>

template<typename T, typename... Args>
void printArgs(T first, Args... rest) {
    std::cout << first << " ";
    
    if constexpr (sizeof...(rest) > 0) { // doesn't compile without constexpr
        printArgs(rest...);
    } else {
        return;
    }
}

int main() {
    printArgs(1, 2, "hello");

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

Q1:为什么程序需要constexpr编译?Q2:条件不应该是吗?因为如果大小是,我再次调用,那么不会是空的?(空着可以吗?)if
sizeof...(rest) > 11printArgsrest

我看到了类似的问题,例如“constexpr if”与“if”的优化 - 为什么需要“constexpr”?,但我不明白这些答案与我的案例有什么关系。

c++ templates if-constexpr

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

标签 统计

c++ ×1

if-constexpr ×1

python ×1

scipy ×1

templates ×1