Quantcast
Channel: Fastest way to append nonzero numpy array elements to list - Stack Overflow
Browsing latest articles
Browse All 3 View Live

Answer by Pierre D for Fastest way to append nonzero numpy array elements to...

I submit that the method of choice, if you are indeed looking for a list output, is:def f(arr, out_list): out_list += arr[arr != 0].tolist()It seems to beat all the other methods mentioned so far in...

View Article



Answer by Mad Physicist for Fastest way to append nonzero numpy array...

Instead of extending a list by all of the elements of a new array, append the array itself. This will make for much fewer and smaller reallocations. You can also pre-allocate a list of Nones up-front...

View Article

Fastest way to append nonzero numpy array elements to list

I want to add all nonzero elements from a numpy array arr to a list out_list. Previous research suggests that for numpy arrays, using np.nonzero is most efficient. (My own benchmark below actually...

View Article
Browsing latest articles
Browse All 3 View Live




Latest Images