这就是我所拥有的
import numpy as np
import scipy.special as sp
ni = input("Digite o valor N Inicial: ") #Ask for a initial N
ne = input ("Digite o valor N Final: ") #Ask for Final N
vet= np.arange(ni,ne+1) #Arrange A Vector with the Ns given
x = np.linspace (-1, 1, 100)
def polinomios (vet, x):
vetr = [0]*(ne-ni+1)
for j in range (ne-ni+1):
for p in range (ne-ni+1):
vetr[p] = sp.legendre(vet[j])(x)
return (vetr)
P = polinomios (vet, x)
print P
我得到这样的
[array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ]), array([ 1. , -0.24609375, 1. ])]
我无法找到一种方法让它看起来像这样,但不要在第一个collunn上放下较小的数字:
[[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]
[-0.24609375 1. 1. ]]
答案 0 :(得分:1)
好的,我确实喜欢@askewchan说并使用了np.array(P)并且它有效。
[[ 1. -0.5 1. ]
[-1. 0. 1. ]
[ 1. 0.375 1. ]
[-1. 0. 1. ]
[ 1. -0.3125 1. ]
[-1. 0. 1. ]
[ 1. 0.2734375 1. ]
[-1. 0. 1. ]
[ 1. -0.24609375 1. ]]