小编xtl*_*luo的帖子

R 中的参数检查

在 R 中,我编写了一个如下函数:

\n\n
fun <- function(A, B, C, D) {}\n
Run Code Online (Sandbox Code Playgroud)\n\n

因此,在这个函数的开头,我必须进行参数检查:

\n\n
    \n
  • 是否缺少一些必需的参数
  • \n
  • 所有参数是否都遵循以下规则:类(数据类型)A 必须在范围 [1:3] 内
  • \n
\n\n

但是关于这些参数,有些是必需的,有些不是,并且每个参数的类(数据类型)必须是我想要的,例如:numericLogical等等......

\n\n

为了实现这一点,我做了类似 \xef\xbc\x9a 的事情

\n\n
if(A Follow_the_rule){}\nif(B Follow_the_rule){}\nif(C Follow_the_rule){}\n...\n
Run Code Online (Sandbox Code Playgroud)\n\n

关于上面的代码,就这么多if语句,我认为这不是参数检查的最佳方法。

\n\n

所以有没有更好的方法来检查 R 中的参数呢?

\n\n

任何帮助将不胜感激。

\n

r parameter-passing

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

用python验证mp3文件的最佳方法

我必须检测文件是否是有效的 mp3 文件。到目前为止,我找到了两个解决方案,包括:

  1. 来自 Peter Carroll 的这个解决方案

  2. 使用try-catch表达式:

try:
    _ = librosa.get_duration(filename=mp3_file_path)
    return True
except:
    return False
Run Code Online (Sandbox Code Playgroud)

上述两种解决方案都有效,但可能有一些缺点,第一个解决方案似乎太复杂而第二个解决方案太慢(以秒为单位,取决于音频的长度)。所以我想知道是否有更好的方法用python验证mp3文件?

谢谢。

python audio-processing

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

C++:int*/float*to char*,为什么使用reinterpret_cast得到不同的结果?

  • int*char*:

    int* pNum = new int[1];
    pNum[0] = 57;
    char* pChar = reinterpret_cast< char* >(pNum);

    float* pFloat = new float[1];
    pFloat[0] = 57; //assign the same value as before
    char* pChar = reinterpret_cast< char* >(pFloat);

结果:pChar [0] ='a';

那么为什么我得到两个不同的结果呢?

谢谢你的帮助.

c++ reinterpret-cast

0
推荐指数
2
解决办法
669
查看次数