Is it possible to sort an array with the smallest values on the bottom left and the highest on the top right?
For example :
I’ve this array :
[[-1. 1. 1.]
[ 1. 1. 1.]
[ 1. 1. 1.]
[ 1. 1. 1.]
[ 1. 1. 1.]
[-1. 1. 1.]]
the sort would be like
[[1. 1. 1.]
[ 1. 1. 1.]
[ 1. 1. 1.]
[ 1. 1. 1.]
[-1. 1. 1.]
[-1. 1. 1.]]
An other example :
[[-1. 1. 1.]
[ 1. 1. 1.]
[ 1. 1. 1.]
[ 4. 3. 1.]
[ 1. 1. 1.]
[-1. 1. 1.]]
Would be :
[[ 1. 1. 4.]
[ 1. 1. 3.]
[ 1. 1. 1.]
[ 1. 1. 1.]
[-1. 1. 1.]
[-1. 1. 1.]]
I Tried Numpy sort :
MyArray.sort()
But it seems not ordering this way.
>Solution :
import numpy as np
x = np.random.rand(6,3)
print(x)
def eiffel_tower_sort(a):
b = a.flatten()
b.sort()
return np.flipud(b.reshape(a.shape, order='F'))
print(eiffel_tower_sort(x))
# randomized / unsorted
[[0.45884748 0.36774746 0.82728461]
[0.46473908 0.22377053 0.43772489]
[0.3596408 0.89647436 0.43567059]
[0.10431368 0.06733271 0.26813345]
[0.45886791 0.57112807 0.51780818]
[0.27032551 0.77706324 0.32331996]]
# sorted
[[0.32331996 0.45886791 0.89647436]
[0.27032551 0.45884748 0.82728461]
[0.26813345 0.43772489 0.77706324]
[0.22377053 0.43567059 0.57112807]
[0.10431368 0.36774746 0.51780818]
[0.06733271 0.3596408 0.46473908]]