random walk - Numpy array comparing 2 arrays element wise with increasing offset of indicies -


This is a version of the problem of random walking using numpy arrays here only 500 times again. To do this, we have to compare a sort array of situations with our offset, close that time and increase the offset.

So far my code is, the problem is in 'when' loop, where I am reviewing the situation in the form of elements in 'ZeroAir', trying to store the last time. / P>

When I run it, I get an indicative error, no results were recorded and a counter that is repeated several times, though the loop has changed to prevent Boolean expression .

Edit: How to obtain a duplicated status with numpy array: 1) Sort the last position array in ascending order. 2) Compare slices with edge offset until you find the post within 0.001 m on that offset, then you compare the position of neighboring posts (offset 1). You can get 18 cases, where in neighboring math two places you can get only two cases. And in three places you will get 0 point. import as import import random MAX_STEP_SIZE = 0.90 # maximum size of the same step [m] NUM_STEPS = 500 # number of steps at a walking distance of [] NUM_WALKS = 10 run [] tolerance random areas of # num = considered points 0.001 # separation of the [M] STEP_TO_RECORD_1 = 100 # records and [] STEP_TO_RECORD_2 = 500 # 2 record first step to analyze the step and analyze [] random. Seed (12345) # ..................................... ........ ......................... distance def distance (posa, posb): "" "two posts b Distance of f "" "Back NP. Abbas (Pause - Pob) # .................................. .... ......................... initial term def initialPosition (): "" "Walker's initial position at the beginning of the random walk" " 0.0 "return DAP genpositions (nSteps, Adiktmstep):" "" "Masestep and after a random move between the maximum step new position return, the last position" genArray1 = (Adiktmstep - (-makssti P)) * (np.random .random (n steps +1)) + (-maxStep) genArray1 [0] = initialPosition () return np.cumsum (genArray1) OneStep = np.zeros (NUM_WALKS) fiveStep = np.zeros (NUM_WALKS) zero Step = np.zeros (NUM_WALKS) walkArray = np.zeros (NUM_WALKS) counter = 1 hitcounter = 0 zerocounter = 0 keepchecking = bool (1) for the ii range (NUM_WALKS): status = (genPositions (NUM_STEPS, MAX_STEP_SIZE)) OneStep [ii] = Position [100] fiveStep [ii] = Position [-1] zeroArray = np.sort (position), while keepchecking == bool (1): zerocounter = 0 in range (for JJ (lane (zeroArray) )): Hitcounter = 0 if distance (zeroArray [JJ + counter], zeroArray [JJ])

Thanks for any help ,

You can directly contrast your posts vector against yourself:

 deltas = np.abs (status [none,] - status [:, none]]   E 

Now, deltas [i, j] step i and the term j is the distance between the positions. You can get your hit by:

  hits = deltas & lt; = TOLERANCE   

To get a close position, you can do the following:

  line, col = np.nonzero (hit) idx = Line & lt; Colonel # diagonal and upper triangular part line = line [idx] col = col [idx]   

get rid of as an example:

  & gt; & Gt; & Gt; Position = genotype (NUM_STEPS, MAX_STEP_SIZE) & gt; & Gt; & Gt; Line, col = np.nonzero (np.abs (status [none ,:] - ... condition [:, none])  gt; & Gt; & Gt; Col = col [idx]> gt; & Gt; & Gt; Line array ([35, 40, 112, 162, 165, 166, 180, 182, 200, 233, 234, 252, 253, 320, 323, 325, 354, 355, 385, 432, 443, 451], DTP = Int64)> gt; & Gt; & Gt; Col array ([64, 78, 115, 240, 392, 246, 334, 430, 463, 366, 413, 401, 315, 380, 365, 348, 438, 435, 401, 483, 473, 492], dtype = Int64)> gt; & Gt; & Gt; Xrange (lane) for jersey: ... print '{0}, {1} - & gt; {2}, {3} '. Format (line [j], colonel [j], position [line [j]] ... ... position [kol [ja]] ... 35, 64 -> 2.56179226445, 2.5627515 9205 40, 78 - & gt; 2. 9 7310455111, 2.97247314695 112, 115 - & gt; 3.40413767436, 3.40420856824 ... 432, 483 - & gt; 10.2560778101, 10.2556475598 443, 473 - & gt; 10.7463713139, 10.7460626764 451, 492 - & gt; 12.3804383241, 12.3805940238    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -