scipy.linalg.

pascal#

scipy.linalg.pascal(n,kind='symmetric',exact=True)[source]#

Returns the n x n Pascal matrix.

The Pascal matrix is a matrix containing the binomial coefficients asits elements.

Parameters:
nint

The size of the matrix to create; that is, the result is an n x nmatrix.

kindstr, optional

Must be one of ‘symmetric’, ‘lower’, or ‘upper’.Default is ‘symmetric’.

exactbool, optional

Ifexact is True, the result is either an array of typenumpy.uint64 (if n < 35) or an object array of Python long integers.Ifexact is False, the coefficients in the matrix are computed usingscipy.special.comb withexact=False. The result will be a floatingpoint array, and the values in the array will not be the exactcoefficients, but this version is much faster thanexact=True.

Returns:
p(n, n) ndarray

The Pascal matrix.

See also

invpascal

Notes

Seehttps://en.wikipedia.org/wiki/Pascal_matrix for more informationabout Pascal matrices.

Added in version 0.11.0.

Examples

>>>fromscipy.linalgimportpascal>>>pascal(4)array([[ 1,  1,  1,  1],       [ 1,  2,  3,  4],       [ 1,  3,  6, 10],       [ 1,  4, 10, 20]], dtype=uint64)>>>pascal(4,kind='lower')array([[1, 0, 0, 0],       [1, 1, 0, 0],       [1, 2, 1, 0],       [1, 3, 3, 1]], dtype=uint64)>>>pascal(50)[-1,-1]25477612258980856902730428600>>>fromscipy.specialimportcomb>>>comb(98,49,exact=True)25477612258980856902730428600
On this page