def RunMovie(self,event = None): import RandomArray start = clock() shift = RandomArray.randint(0,0,(2,)) NumFrames = 50 for i in range(NumFrames): points = self.LEs.Points shift = RandomArray.randint(-5,5,(2,)) points += shift self.LEs.SetPoints(points) self.Canvas.Draw() print "running the movie took %f seconds to disply %i frames"%((clock() - start),NumFrames)
def MakeRandomPartitionProblem(N, M): """ Returns a random series of N integers in the range 1 < p < 2**M, guaranteed to sum to an even number. Use RandomArray.randint to generate a length N vector S of the appropriate range. While sum(S) mod 2 is not zero, re-generate S. """ intSize = 2**M S = RandomArray.randint(1, intSize + 1, N) while sum(S) % 2 != 0: S = RandomArray.randint(1, intSize + 1, N) return S
def RunMovie(self, event=None): import RandomArray start = clock() shift = RandomArray.randint(0, 0, (2, )) NumFrames = 50 for i in range(NumFrames): points = self.LEs.Points shift = RandomArray.randint(-5, 5, (2, )) points += shift self.LEs.SetPoints(points) self.Canvas.Draw() print "running the movie took %f seconds to disply %i frames" % ( (clock() - start), NumFrames)
def test_sparse_vs_dense(self): RandomArray.seed(0) # For reproducability for s, l in (100, 100000), (10000, 100000), (100000, 100000): small = Numeric.sort(RandomArray.randint(0, 100000, (s,))) large = Numeric.sort(RandomArray.randint(0, 100000, (l,))) sparse1 = soomfunc.sparse_intersect(small, large) sparse2 = soomfunc.sparse_intersect(large, small) dense1 = soomfunc.dense_intersect(small, large) dense2 = soomfunc.dense_intersect(large, small) self.assertEqual(sparse1, sparse2) self.assertEqual(dense1, dense2) self.assertEqual(sparse1, dense1)
def readfiles(self): ncopy = 2 for j in range(ncopy): infile = open('/Users/rfinn/SDSS/fieldDR4/myclusters.cat', 'r') for line in infile: if line.find('#') > -1: continue t = line.split() self.id.append(float(t[0])) #C4 id name self.r200.append(float(t[3])) #R200 in Mpc self.sigma.append(float(t[4])) #sigma in km/s self.z.append(float(t[1])) c1 = Rand.randint(0, len( g.x1all)) #center on random galaxy in gal catalog #c2=Rand.randint(0,len(g.x1))#center on random galaxy in gal catalog #c3=Rand.randint(0,len(g.x1))#center on random galaxy in gal catalog self.x1.append(g.x1all[c1]) self.x2.append(g.x2all[c1]) self.x3.append(g.x3all[c1]) #c1=Rand.random()#center on random position in simulation #c2=Rand.random()#center on random position in simulation #c3=Rand.random()#center on random #self.x1.append(c1*simL) #self.x2.append(c2*simL) #self.x3.append(c3*simL) infile.close() self.r200 = N.array(self.r200, 'd') self.sigma = N.array(self.sigma, 'd') self.z = N.array(self.z, 'd') self.x1 = N.array(self.x1, 'd') self.x2 = N.array(self.x2, 'd') self.x3 = N.array(self.x3, 'd')
def random_tree(labels): """ Given a list of labels, create a list of leaf nodes, and then one by one pop them off, randomly grafting them on to the growing tree. Return the root node. """ assert len(labels) > 2 import RandomArray; RandomArray.seed() leaves = [] for label in labels: leaves.append(Fnode(istip=1, label=label)) leaf_indices = list(RandomArray.permutation(len(leaves))) joined = [leaves[leaf_indices.pop()]] remaining = leaf_indices while remaining: i = RandomArray.randint(0, len(joined)-1) c1 = joined[i] if c1.back: n = c1.bisect() else: n = InternalNode() n.add_child(c1) c = leaves[remaining.pop()] n.add_child(c) joined.append(c) joined.append(n) for node in joined: if not node.back: node.isroot = 1 return node
def test2(shape=(100,100)): dl = DynamicLattice.DynamicLattice(shape) a = RandomArray.randint(0, 2, shape) dl.display(a) for i in range(shape[0]/2): for j in range(shape[0]/2): a[i,j] = 0 dl.display(a, (i,j))
def sampled_ds(parent_dataset, sample, name=None, filter_label=None, **kwargs): parent_len = len(parent_dataset) samp_len = int(parent_len * sample) record_ids = Numeric.sort(RandomArray.randint(0, parent_len, samp_len)) if name is None: name = 'samp%02d_%s' % (sample * 100, parent_dataset.name) if filter_label is None: filter_label = '%.3g%% sample' % (sample * 100) return FilteredDataset(parent_dataset, record_ids, name=name, filter_label=filter_label, **kwargs)
def sampled_ds(parent_dataset, sample, name=None, filter_label=None, **kwargs): parent_len = len(parent_dataset) samp_len = int(parent_len * sample) record_ids = Numeric.sort(RandomArray.randint(0, parent_len, samp_len)) if name is None: name = 'samp%02d_%s' % (sample * 100, parent_dataset.name) if filter_label is None: filter_label = '%.3g%% sample' % (sample * 100) return FilteredDataset(parent_dataset, record_ids, name=name, filter_label=filter_label, **kwargs)
from pysparse.spmatrix import * import RandomArray import time n = 1000 nnz = 50000 A = ll_mat(n, n, nnz) R = RandomArray.randint(0, n, (nnz,2)) t1 = time.clock() for k in xrange(nnz): A[R[k,0],R[k,1]] = k print 'Time for populating matrix: %8.2f sec' % (time.clock() - t1, ) print A.nnz B = A[:,:] A.shift(-1.0, B) print A
def test(shape=(100,100)): dl = DynamicLattice.DynamicLattice(shape) for n in range(20): a = RandomArray.randint(0, 2, shape) dl.display(a)
def randomBits(length): address = RandomArray.randint(0, 2, length) return address
def randomBits(length): address = RandomArray.randint(0, 2, length) return address
import wx import numarray from numarray import random_array import RandomArray # the Numeric version import time NumLinePoints = 5000 NumPointPoints = 5000 ## Make some random data to draw things with. MaxX = 500 LinesPoints = random_array.randint(1, MaxX, (NumLinePoints,2) ) #PointsPoints = random_array.randint(1, MaxX, (NumPointPoints,2) ) PointsPoints = RandomArray.randint(1, MaxX, (NumPointPoints,2) ) # Numeric class TestFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "DrawLines Test", wx.DefaultPosition, size=(500,500), style=wx.DEFAULT_FRAME_STYLE | wx.NO_FULL_REPAINT_ON_RESIZE) ## Set up the MenuBar MenuBar = wx.MenuBar() file_menu = wx.Menu() ID_EXIT_MENU = wx.NewId()