Altamiro
Altamiro

Reputation: 63

Sorting with np.sort but the result is not right

This is what i have

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

And i get like this

[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.        ])]

And I cant find a way to get it looks like this, but without putting the smaller number on the first 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.        ]]

Upvotes: 1

Views: 2513

Answers (1)

Altamiro
Altamiro

Reputation: 63

Ok, I did like @askewchan said and used np.array(P) and it worked.

[[ 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.        ]]

Upvotes: 1

Related Questions