{ } Raw JSON

bundles / scipy latest / scipy / special / _basic / stirling2

function

scipy.special._basic:stirling2

source: /scipy/special/_basic.py :3136

Signature

def   stirling2 ( N K * exact = False )

Summary

Generate Stirling number(s) of the second kind.

Extended Summary

Stirling numbers of the second kind count the number of ways to partition a set with N elements into K non-empty subsets.

The values this function returns are calculated using a dynamic program which avoids redundant computation across the subproblems in the solution. For array-like input, this implementation also avoids redundant computation across the different Stirling number calculations.

The numbers are sometimes denoted

see [1] for details. This is often expressed-verbally-as "N subset K".

Parameters

N : int, ndarray

Number of things.

K : int, ndarray

Number of non-empty subsets taken.

exact : bool, optional

Uses dynamic programming (DP) with floating point numbers for smaller arrays and uses a second order approximation due to Temme for larger entries of N and K that allows trading speed for accuracy. See [2] for a description. Temme approximation is used for values n>50. The max error from the DP has max relative error 4.5*10^-16 for n<=50 and the max error from the Temme approximation has max relative error 5*10^-5 for 51 <= n < 70 and 9*10^-6 for 70 <= n < 101. Note that these max relative errors will decrease further as n increases.

Returns

val : int, float, ndarray

The number of partitions.

Notes

  • If N < 0, or K < 0, then 0 is returned.

  • If K > N, then 0 is returned.

The output type will always be int or ndarray of object. The input must contain either numpy or python integers otherwise a TypeError is raised.

Examples

import numpy as np
from scipy.special import stirling2
k = np.array([3, -1, 3])
n = np.array([10, 10, 9])
stirling2(n, k)

See also

comb

The number of combinations of N things taken k at a time.

Aliases

  • scipy.special.stirling2

Referenced by

This package