MCPcopy Index your code
hub / github.com/numpy/numpy / vander

Function vander

numpy/lib/_twodim_base_impl.py:588–674  ·  view source on GitHub ↗

Generate a Vandermonde matrix. The columns of the output matrix are powers of the input vector. The order of the powers is determined by the `increasing` boolean argument. Specifically, when `increasing` is False, the `i`-th output column is the input vector raised element-wise

(x, N=None, increasing=False)

Source from the content-addressed store, hash-verified

586# Originally borrowed from John Hunter and matplotlib
587@array_function_dispatch(_vander_dispatcher)
588def vander(x, N=None, increasing=False):
589 """
590 Generate a Vandermonde matrix.
591
592 The columns of the output matrix are powers of the input vector. The
593 order of the powers is determined by the `increasing` boolean argument.
594 Specifically, when `increasing` is False, the `i`-th output column is
595 the input vector raised element-wise to the power of ``N - i - 1``. Such
596 a matrix with a geometric progression in each row is named for Alexandre-
597 Theophile Vandermonde.
598
599 Parameters
600 ----------
601 x : array_like
602 1-D input array.
603 N : int, optional
604 Number of columns in the output. If `N` is not specified, a square
605 array is returned (``N = len(x)``).
606 increasing : bool, optional
607 Order of the powers of the columns. If True, the powers increase
608 from left to right, if False (the default) they are reversed.
609
610 Returns
611 -------
612 out : ndarray
613 Vandermonde matrix. If `increasing` is False, the first column is
614 ``x^(N-1)``, the second ``x^(N-2)`` and so forth. If `increasing` is
615 True, the columns are ``x^0, x^1, ..., x^(N-1)``.
616
617 See Also
618 --------
619 polynomial.polynomial.polyvander
620
621 Examples
622 --------
623 >>> import numpy as np
624 >>> x = np.array([1, 2, 3, 5])
625 >>> N = 3
626 >>> np.vander(x, N)
627 array([[ 1, 1, 1],
628 [ 4, 2, 1],
629 [ 9, 3, 1],
630 [25, 5, 1]])
631
632 >>> np.column_stack([x**(N-1-i) for i in range(N)])
633 array([[ 1, 1, 1],
634 [ 4, 2, 1],
635 [ 9, 3, 1],
636 [25, 5, 1]])
637
638 >>> x = np.array([1, 2, 3, 5])
639 >>> np.vander(x)
640 array([[ 1, 1, 1, 1],
641 [ 8, 4, 2, 1],
642 [ 27, 9, 3, 1],
643 [125, 25, 5, 1]])
644 >>> np.vander(x, increasing=True)
645 array([[ 1, 1, 1, 1],

Callers 3

polyfitFunction · 0.90
test_basicMethod · 0.90
test_dtypesMethod · 0.90

Calls 3

emptyFunction · 0.85
accumulateMethod · 0.80
asarrayFunction · 0.50

Tested by 2

test_basicMethod · 0.72
test_dtypesMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…