MCPcopy Create free account
hub / github.com/numpy/numpy / vander

Function vander

numpy/lib/twodim_base.py:535–622  ·  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

533# Originally borrowed from John Hunter and matplotlib
534@array_function_dispatch(_vander_dispatcher)
535def vander(x, N=None, increasing=False):
536 """
537 Generate a Vandermonde matrix.
538
539 The columns of the output matrix are powers of the input vector. The
540 order of the powers is determined by the `increasing` boolean argument.
541 Specifically, when `increasing` is False, the `i`-th output column is
542 the input vector raised element-wise to the power of ``N - i - 1``. Such
543 a matrix with a geometric progression in each row is named for Alexandre-
544 Theophile Vandermonde.
545
546 Parameters
547 ----------
548 x : array_like
549 1-D input array.
550 N : int, optional
551 Number of columns in the output. If `N` is not specified, a square
552 array is returned (``N = len(x)``).
553 increasing : bool, optional
554 Order of the powers of the columns. If True, the powers increase
555 from left to right, if False (the default) they are reversed.
556
557 .. versionadded:: 1.9.0
558
559 Returns
560 -------
561 out : ndarray
562 Vandermonde matrix. If `increasing` is False, the first column is
563 ``x^(N-1)``, the second ``x^(N-2)`` and so forth. If `increasing` is
564 True, the columns are ``x^0, x^1, ..., x^(N-1)``.
565
566 See Also
567 --------
568 polynomial.polynomial.polyvander
569
570 Examples
571 --------
572 >>> x = np.array([1, 2, 3, 5])
573 >>> N = 3
574 >>> np.vander(x, N)
575 array([[ 1, 1, 1],
576 [ 4, 2, 1],
577 [ 9, 3, 1],
578 [25, 5, 1]])
579
580 >>> np.column_stack([x**(N-1-i) for i in range(N)])
581 array([[ 1, 1, 1],
582 [ 4, 2, 1],
583 [ 9, 3, 1],
584 [25, 5, 1]])
585
586 >>> x = np.array([1, 2, 3, 5])
587 >>> np.vander(x)
588 array([[ 1, 1, 1, 1],
589 [ 8, 4, 2, 1],
590 [ 27, 9, 3, 1],
591 [125, 25, 5, 1]])
592 >>> np.vander(x, increasing=True)

Callers 3

polyfitFunction · 0.90
test_basicMethod · 0.90
test_dtypesMethod · 0.90

Calls 4

promote_typesFunction · 0.85
accumulateMethod · 0.80
asarrayFunction · 0.50
emptyFunction · 0.50

Tested by 2

test_basicMethod · 0.72
test_dtypesMethod · 0.72