I have one simple program below:
import numpy as np
arr = np.random.randn(8)
new = arr.sort()
new1 = np.sort(arr)
print new
print new1
I expected the two new arrays to be the same a sorted array, but instead, new
is None
, new1
is what I expected, what is the difference between two methods to sort?
From the documentation for numpy.ndarray.sort
:
Sort an array, in-place.
If you want a sorted copy of the original array, rather than sorting in place, you should use numpy.sort
, which returns a copy, as you saw.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With