scipy.special.
bernoulli#
- scipy.special.bernoulli(n)[source]#
伯努利数 B0..Bn(包括)。
- 参数:
- nint
指示要生成的伯努利序列中的项数。
- 返回:
- ndarray
伯努利数
[B(0), B(1), ..., B(n)]
。
参考
[1]Zhang, Shanjie and Jin, Jianming. “Computation of Special Functions”, John Wiley and Sons, 1996. https://people.sc.fsu.edu/~jburkardt/f77_src/special_functions/special_functions.html
[2]“Bernoulli number”, Wikipedia, https://en.wikipedia.org/wiki/Bernoulli_number
示例
>>> import numpy as np >>> from scipy.special import bernoulli, zeta >>> bernoulli(4) array([ 1. , -0.5 , 0.16666667, 0. , -0.03333333])
维基百科文章 ([2]) 指出了伯努利数和 zeta 函数之间的关系,
B_n^+ = -n * zeta(1 - n)
对于n > 0
>>> n = np.arange(1, 5) >>> -n * zeta(1 - n) array([ 0.5 , 0.16666667, -0. , -0.03333333])
请注意,在维基百科文章中使用的符号中,
bernoulli
计算B_n^-
(即它使用约定B_1
是 -1/2)。 上面给出的关系是对于B_n^+
,所以 0.5 的符号与bernoulli(4)
的输出不匹配。