NumPy排序函数返回None [英] NumPy sort function returns None
本文介绍了NumPy排序函数返回None的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下面有一个简单的程序:
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
我希望这两个新数组与排序数组相同,但是new
是None
,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?
推荐答案
就地对数组进行排序.
Sort an array, in-place.
如果要原始数组的排序副本,而不是就地排序,则应使用numpy.sort
,它会返回一个副本,如您所见.
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.
这篇关于NumPy排序函数返回None的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文