Python| Numpy np.lagvander2d() 方法
借助np.lagvander2d()
方法,我们可以从给定的具有度数的数组中获取伪范德蒙矩阵,并使用np.lagvander2d()
方法作为参数传递。
Syntax : np.lagvander2d(x, y, deg)
Parameters:
x, y :[ array_like ] Array of points. The dtype is converted to float64 or complex128 depending on whether any of the elements are complex. If x is scalar it is converted to a 1-D array
deg :[int] Degree of the resulting matrix.
Return : Return the matrix having size i.e array.size + (degree + 1).
示例 #1:
在这个例子中,我们可以看到通过使用np.lagvander2d()
方法,我们能够使用这种方法得到伪范德蒙矩阵。
# import numpy
import numpy as np
import numpy.polynomial.laguerre as geek
# using np.lagvander() method
ans = geek.lagvander2d((1, 3, 5, 7), (2, 4, 6, 8), [2, 2])
print(ans)
输出 :
[[ 1. -1. -1. 0. -0. -0. -0.5 0.5 0.5]
[ 1. -3. 1. -2. 6. -2. -0.5 1.5 -0.5]
[ 1. -5. 7. -4. 20. -28. 3.5 -17.5 24.5]
[ 1. -7. 17. -6. 42. -102. 11.5 -80.5 195.5]]
示例 #2:
# import numpy
import numpy as np
import numpy.polynomial.laguerre as geek
ans = geek.lagvander2d((1, 2, 3, 4), (5, 6, 7, 8), [3, 3])
print(ans)
输出 :
[[ 1. -4. 3.5 2.66666667 0. -0.
0. 0. -0.5 2. -1.75 -1.33333333
-0.66666667 2.66666667 -2.33333333 -1.77777778]
[ 1. -5. 7. 1. -1. 5.
-7. -1. -1. 5. -7. -1.
-0.33333333 1.66666667 -2.33333333 -0.33333333]
[ 1. -6. 11.5 -3.66666667 -2. 12.
-23. 7.33333333 -0.5 3. -5.75 1.83333333
1. -6. 11.5 -3.66666667]
[ 1. -7. 17. -12.33333333 -3. 21.
-51. 37. 1. -7. 17. -12.33333333
2.33333333 -16.33333333 39.66666667 -28.77777778]]