小编Ian*_*ker的帖子

Python中的舍入/舍入标准

我正在将一个MATLAB代码移植到Python 3.5.1中,我发现了一个浮点数舍入问题.

在MATLAB中,以下数字向上舍入到第6个小数位:

fprintf(1,'%f', -67.6640625);
-67.664063
Run Code Online (Sandbox Code Playgroud)

在Python,而另一方面,下面的数字将被四舍五入至第6位小数:

print('%f' % -67.6640625)
-67.664062
Run Code Online (Sandbox Code Playgroud)

有趣的是,如果该号码是"-67.6000625",则取整起来,即使在Python:

print('%f' % -67.6000625)
-67.600063
Run Code Online (Sandbox Code Playgroud)

......为什么会这样?在Python中舍入/增加的标准是什么?(我相信这与处理十六进制值有关.)

更重要的是,我该如何防止这种差异?我应该创建一个python代码,它可以重现与MATLAB生成的完全相同的输出.

python matlab rounding

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

Python中科学记数法中的指数数字

在 Python 中,科学记数法总是给我 2 位数的指数:

print('%17.8E\n' % 0.0665745511651039)
6.65745512E-02
Run Code Online (Sandbox Code Playgroud)

但是,我非常希望有 3 个数字,例如:

6.65745512E-002
Run Code Online (Sandbox Code Playgroud)

我们可以使用 Python 中的内置配置/函数来做到这一点吗?

我知道我的问题与以下问题基本相同:Python - number of digits in exponent,但这个问题是 4 年前提出的,我不想调用这样的函数一千次。我希望现在应该有更好的解决方案。

python scientific-notation exponent

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

如何在五线谱上方显示和弦名称

我是 Lilypond 的新手,正在尝试编写带有和弦名称和低音线的乐谱。我想在五线谱上方显示和弦名称;然而,它们实际上显示在员工下方。baseChords我以前写过baseMelody,但根本没有帮助。这是我的整个代码:

baseChords = \chords {
    \set chordChanges = ##t
    c1:m7 f:7 bes:maj7 ees:maj7 
    a:m7.5- d:7.13- g:m6 g:m6 
}

baseMelody = \fixed c {
  \language "english"
c4 c ef g, 
f, f, a, c 
bf, bf, d f, 
ef ef g, bf, 
a, a, c ef 
d d fs, a, 
g, g, bf, d 
g, g, bf, d 
g,1
}

melody = {
  \key g \minor
  \clef bass
  \tempo 4 = 108
  <<
  \baseChords …
Run Code Online (Sandbox Code Playgroud)

chord lilypond

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

安装scikits.samplerate失败

我想使用"scikits.samplerate",但安装失败.我正在使用Windows10(64位)与Anaconda的Python 3.51.

首先,我遵循了这条指令:https: //scikits.appspot.com/samplerate

>pip install scikits.samplerate Collecting scikits.samplerate   Using cached scikits.samplerate-0.3.3.tar.gz
    Complete output from command python setup.py egg_info:
    SamplerateInfo:
      libraries samplerate not found in c:\users\username\anaconda3\lib
      libraries samplerate not found in C:\
      libraries samplerate not found in c:\users\username\anaconda3\libs
    Traceback (most recent call last):
      File "scikits\samplerate\setup.py", line 15, in configuration
        sf_config = sf_info.get_info(2)
      File "c:\users\username\anaconda3\lib\site-packages\numpy\distutils\system_info.py", line 568, in get_info
        raise self.notfounderror(self.notfounderror.__doc__)
    numpy.distutils.system_info.NotFoundError: Some third-party program or library is not found.

    During handling of the above exception, another exception occurred: …
Run Code Online (Sandbox Code Playgroud)

python install scikits anaconda

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

定义有什么问题?

我正在尝试使用Windows10上的Visual Studio VC++ 2015编译"libsamplerate.dll",请参阅:http://www.mega-nerd.com/SRC/win32.html.

然后,我得到以下错误:

termination_test.c
.\tests\termination_test.c(82): error C2057: expected constant expression
.\tests\termination_test.c(82): error C2466: cannot allocate an array of constant size 0
.\tests\termination_test.c(82): error C2133: 'in': unknown size
.\tests\termination_test.c(83): error C2057: expected constant expression
.\tests\termination_test.c(83): error C2466: cannot allocate an array of constant size 0
.\tests\termination_test.c(83): error C2133: 'out': unknown size
NMAKE : fatal error U1077: '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\cl.exe"' : return code '0x2'
Run Code Online (Sandbox Code Playgroud)

"termination_test.c"最初来自:http: //www.mega-nerd.com/SRC/download.html ,这里是导致错误的函数:

static void
simple_test (int …
Run Code Online (Sandbox Code Playgroud)

c arrays

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