Posts: 6
Threads: 2
Joined: Jan 2020
[1.4472136]
[1.28]
[1.98994949]
[0.00211989]
[1.8]
[0.63960072]
[0.85857864]
[0.4]
[0.01005051]
Hi , I just want to Sort the above in Ascending order , All are 1D arrays
Posts: 1,838
Threads: 2
Joined: Apr 2017
What have you tried or at least thought about?
Posts: 2,342
Threads: 62
Joined: Sep 2016
Something like
from operator import itemgetter
your_list = ... # list of 1-D lists
your_list.sort(key=itemgetter(0)) That said, as ndc85430 said, your posts should generally show your attempt.
Posts: 99
Threads: 1
Joined: Dec 2019
There are MANY ways to do this but you haven't given us any idea what your actual goal is. There are no base "arrays" in Python. You have shown us 9 python lists, each with 1 float number in them. If you want to sort them, put them all into a list and use the built-in sorted() or list.sort() function.
https://docs.python.org/2/howto/sorting....rtinghowto
"So, brave knights, if you do doubt your courage or your strength, come no further, for death awaits you all with nasty, big, pointy teeth!" - Tim the Enchanter
Posts: 1,950
Threads: 8
Joined: Jun 2018
Maybe I am stupid but what is wrong with just:
>>> sorted([[1.1], [1.0], [1.05]])
[[1.0], [1.05], [1.1]]
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 2,342
Threads: 62
Joined: Sep 2016
(Jan-10-2020, 07:35 PM)perfringo Wrote: Maybe I am stupid For the OP's purposes, yours is probably equivalent to mine, and as you implied, simpler. In retrospect I should have used a lambda instead of a mysterious built-in library too.
Posts: 6
Threads: 2
Joined: Jan 2020
Thanks
Actually my problem is to list the smallest Cosine distance in Graph
S= [(1,2),(3,4),(-1,1),(6,-7),(0, 6),(-5,-8),(-1,-1),(6,0),(1,-1)] # these are the list of x & y axix
P= (3,-4) # so here i have to find the distance between each tuple in S with P & find the top 5 lowest distance axis
below is the code i have written to find the cosine distance between each Tuple in S & P .
import math
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
S= [(1,2),(3,4),(-1,1),(6,-7),(0, 6),(-5,-8),(-1,-1),(6,0),(1,-1)]
for i in range (0,len(S)):
#print(S[i])
#print(np.ndim(S[i]))
J=np.reshape(S[i],(1,2))
#print(J)
#print(np.ndim(J))
P=[(3,-4)]
#print(np.ndim(P))
A=cosine_similarity(J,P)
#print(A)
C=1-A # Cosine Distance = 1-cosine similarity
#print©
#print(np.ndim©)
D=np.reshape(C,(1))
#print(np.ndim(D))
print(D)
# if i print D , i am getting the below Cosine distance
[1.4472136]
[1.28]
[1.98994949]
[0.00211989]
[1.8]
[0.63960072]
[0.85857864]
[0.4]
[0.01005051]
now i want to Sort 5 distance in ascending order (Less distance) & to print the respective X & Y axis
Posts: 6
Threads: 2
Joined: Jan 2020
Actually my problem is to list the smallest Cosine distance in Graph
S= [(1,2),(3,4),(-1,1),(6,-7),(0, 6),(-5,-8),(-1,-1),(6,0),(1,-1)] # these are the list of x & y axix
P= (3,-4) # so here i have to find the distance between each tuple in S with P & find the top 5 lowest distance axis
below is the code i have written to find the cosine distance between each Tuple in S & P .
import math
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
S= [(1,2),(3,4),(-1,1),(6,-7),(0, 6),(-5,-8),(-1,-1),(6,0),(1,-1)]
for i in range (0,len(S)):
#print(S[i])
#print(np.ndim(S[i]))
J=np.reshape(S[i],(1,2))
#print(J)
#print(np.ndim(J))
P=[(3,-4)]
#print(np.ndim(P))
A=cosine_similarity(J,P)
#print(A)
C=1-A # Cosine Distance = 1-cosine similarity
#print©
#print(np.ndim©)
D=np.reshape(C,(1))
#print(np.ndim(D))
print(D)
# if i print D , i am getting the below Cosine distance
[1.4472136]
[1.28]
[1.98994949]
[0.00211989]
[1.8]
[0.63960072]
[0.85857864]
[0.4]
[0.01005051]
now i want to Sort 5 distance in ascending order (Less distance) & to print the respective X & Y axis
Posts: 6
Threads: 2
Joined: Jan 2020
(Jan-10-2020, 06:47 PM)Marbelous Wrote: There are MANY ways to do this but you haven't given us any idea what your actual goal is. There are no base "arrays" in Python. You have shown us 9 python lists, each with 1 float number in them. If you want to sort them, put them all into a list and use the built-in sorted() or list.sort() function.
https://docs.python.org/2/howto/sorting....rtinghowto
Thanks
Actually my problem is to list the smallest Cosine distance in Graph
S= [(1,2),(3,4),(-1,1),(6,-7),(0, 6),(-5,-8),(-1,-1),(6,0),(1,-1)] # these are the list of x & y axix
P= (3,-4) # so here i have to find the distance between each tuple in S with P & find the top 5 lowest distance axis
below is the code i have written to find the cosine distance between each Tuple in S & P .
import math
import numpy as np
from sklearn.metrics.pairwise import cosine_similarity
S= [(1,2),(3,4),(-1,1),(6,-7),(0, 6),(-5,-8),(-1,-1),(6,0),(1,-1)]
for i in range (0,len(S)):
#print(S[i])
#print(np.ndim(S[i]))
J=np.reshape(S[i],(1,2))
#print(J)
#print(np.ndim(J))
P=[(3,-4)]
#print(np.ndim(P))
A=cosine_similarity(J,P)
#print(A)
C=1-A # Cosine Distance = 1-cosine similarity
#print©
#print(np.ndim©)
D=np.reshape(C,(1))
#print(np.ndim(D))
print(D)
# if i print D , i am getting the below Cosine distance
[1.4472136]
[1.28]
[1.98994949]
[0.00211989]
[1.8]
[0.63960072]
[0.85857864]
[0.4]
[0.01005051]
now i want to Sort 5 distance in ascending order (Less distance) & to print the respective X & Y axis
|