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
Post a Comment