python - Can I cleanse a numpy array without a loop? -


perhaps not such big deal, breaks heart follow this:

deltas = data[1:] - data[:-1]

with this:

for in range(len(deltas)):         if deltas[i] < 0: deltas[i] = 0         if deltas[i] > 100: deltas[i] = 0 

for particular example...is there better way cleansing part?

question part two: if cleansing rules more complicated, or less complicated example. example, might want change negative numbers zero. or, might doing more complicated mapping.

import numpy np deltas=np.diff(data) deltas[deltas<0]=0 deltas[deltas>100]=0 

also possible, , bit quicker

deltas[(deltas<0) | (deltas>100)]=0 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -