重排陣【難度:2級】:
答案1:
import numpy as np
def reorder(arr, n):
a = np.array(arr)
return np.partition(a, n).tolist()
答案2:
import numpy
def reorder(arr, n):
k = numpy.argpartition(arr, n)
return [ arr[i] for i in k]
答案3:
import numpy as np
def reorder(arr, n):
res = np.argpartition(arr, n)
return [arr[i] for i in res]
答案4:
def reorder(arr, n):
from numpy import array,partition as pt
return list(pt(array(arr),n)) # [pt(array(arr),n)]
答案5:
import numpy as np
reorder = lambda arr, n: list(np.partition(np.array(arr), n))
答案6:
import numpy as np
def reorder(arr, n): return np.partition(arr, n).tolist()
答案7:
import numpy as np
def reorder(arr, n):
return np.partition(np.array(arr), n).tolist()
答案8:
import numpy as np
def reorder(xs, n):
return guess_order(xs, n)
def guess_order(xs, n):
return np.partition(xs, n).tolist()
答案9:
import numpy
reorder = lambda Q,S : list(numpy.partition(Q,S))
答案10:
import numpy as np
def reorder(arr, n):
return list(np.partition(np.array(arr), n))
歡迎各位同學加羣討論,一起學習,共同成長!