Initial commit.
#!/usr/bin/python
import pylab as pl
def makezero(B, gap=None):
B = pl.array(B) # B is a vector!
B = B.squeeze()
if len(B.shape)!=1:
print "B must be a vector!"
exit()
if gap == None:
gap = 1e8
temp = B[pl.find(B)]
temp = -pl.sort(-abs(temp))
ratio = temp[:-1]/pl.float32(temp[1:])
if pl.find(ratio>gap).size != 0:
min_ind = min(pl.find(ratio>gap))
our_eps = temp[min_ind+1]
zeroind = pl.find(abs(B)<=our_eps)
B[zeroind] = 0
return pl.atleast_2d(B)
if __name__== "__main__":
B = pl.array([2,3,.000000000004,5,.00006])
print B
B = makezero(B)
print B