import numpy as np a = np.array([9, 0, 3, 8, 1, 0, 0, 0]) def key(a): return a != 0 print(a[np.argsort(key(a))])
Standard input is empty
[0 0 0 0 9 3 8 1]
The brand new service which powers Ideone!
Widget for compiling and running the source code in a web browser!