This is a pre-release version (2.0.0.dev0+git20260907.41eeb59).Go to latest (1.18.0)
{ } Raw JSON

bundles / scipy 2.0.0.dev0+git20260907.41eeb59 / scipy / special / _basic / bernoulli

function

scipy.special._basic:bernoulli

source: build-install/usr/lib/python3.14/site-packages/scipy/special/_basic.py:2108

Signature

def bernoulli(n)

Summary

Bernoulli numbers B_0 through B_n (inclusive).

Parameters

n : int

Index of the last Bernoulli number to return. Non-integer values are cast to integers. Must be non-negative.

Returns

: ndarray

The Bernoulli numbers [B(0), B(1), ..., B(n)].

Examples

import numpy as np
from scipy.special import bernoulli, zeta
✓
bernoulli(4)
✗
array([ 1.   , -0.5  ,  0.167,  0.   , -0.033])
The Wikipedia article ([1]_) points out the relationship between the Bernoulli numbers and the zeta function, ``B_n^+ = -n * zeta(1 - n)`` for ``n > 0``:
n = np.arange(1, 5)
✓
-n * zeta(1 - n)
✗
array([ 0.5  ,  0.167, -0.   , -0.033])
Note that, in the notation used in the Wikipedia article, `bernoulli` computes ``B_n^-`` (i.e. it used the convention that ``B_1`` is -1/2). The relation given above is for ``B_n^+``, so the sign of 0.5 does not match the output of ``bernoulli(4)``.

Aliases

  • scipy.special.bernoulli