Python numpy performance - selection on very large array

Viewed 1524

I'm trying to optimize some code and one of the time consuming operations is the following:

import numpy as np
survivors = np.where(a > 0)[0]
pos = len(survivors)
a[:pos] = a[survivors]
b[:pos] = b[survivors]
c[:pos] = c[survivors]

In my code a is a very large (more than 100000) NumPy array of floats. Many of them will be 0.

Is there a way to speed this up?

1 Answers
Related