Complexity of np.argsort()

75 Views Asked by At

Is there a difference in memory consumption or between np.argsort(array)[::-1][:10] and np.argsort(array)[-10:]?

they both return the same numbers (same answer) but my university doctor said that the first one is worst because it takes up more space using make a new descending array , so I want to make sure .

1

There are 1 best solutions below

1
juanpa.arrivillaga On

No, for numpy.ndarray objects, those slices create views, and creating a view only requires a small, constant amount of extra space.

From the docs:

All arrays generated by basic slicing are always views of the original array.

Your professor is probably assuming that slicing works the same was as with built-in list objects, which indeed would require extra copies.