Reputation: 21
I have A = np.array([43, 66, 34, 55, 78, 105, 2])
I need to sort the A[i] by increase if number is divisible by 2
Answer will be array([ 43, 2, 34, 55, 66, 105, 78])
How can I do this using np.sort()?
Upvotes: 2
Views: 93
Reputation: 5949
You could use boolean indexing and set sorted values in place:
idx = A % 2 == 0
A[idx] = np.sort(A[idx])
Upvotes: 4