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 .
No, for
numpy.ndarrayobjects, those slices create views, and creating a view only requires a small, constant amount of extra space.From the docs:
Your professor is probably assuming that slicing works the same was as with built-in
listobjects, which indeed would require extra copies.