matplotlib - python randomwalk not walking -


My professor has given me this code and the only part I think is the TODO area. I'm still new to Python and This type of project has never touched, so I am confused instead. All this plot is to get the plot graphed image.

  import math, random, pylab class space (object): def __init __ (self, x, y): self.x = float (x) self Y = float (y, def) (self, xc, yc): return location (self.x + float (xc), self.y + float (yc)) def getCoords (self): self return. Def DDICCT (Self, Other): Bull, Oye = Other.Gate Cores () xDist = self.x - Ox yDist = self.y - Oye Return Mathematics.Critt (xDist ** 2 + yDist ** 2) Class CompassPt ( Object: Possibles: self.pt = pt else: raise ValueError ('object'): possibles = ('n', 's', 'e', ​​'w') def __init __ (self, pt) Def move (self, dist): if self.pt == 'N': Return (0, dist) elif self.pt == 'S': return (0, -dist) Elif self .pt == 'E': Return (dist, 0) elif self.pt == 'W': Returns (-Dist, 0) Other: Increase ValueError (in 'CompassPt.move') Square field (object): Def __int __ (self, drunk In, location): self Drugs = Drunk self. Loc = loc def move (self, cp, distribution): old people = self.loc xc, yc = cp.move (dist) self.loc = oldLoc (self): return self. Drunk class drunk (object): def __init __ (self, name): self. Name = name def move (self, field, time = 1): if field. GetDrunk ()! = Self: ValueError for 'I' in range ('Drunk.' Drunken area ''): pt = CompassPt (random.choice (CompassPt. Possibles)) field.move (pt, 1) < / Code> 

Here is the part I have to do and have tried to do so my graph is not worthy yet. I get a dot in the middle of the graph, unless it is random at one place If possible, if it is possible. , F): start = f.getLoc () # for distance = [0.0] in range T (1, time + 1): # todo f.getDrunk () Move (f) newLoc = f.getLoc () distance = NewLoc.getDist (start) distance. Append (distance) xcoords, ycoords = distance [:: 2], distance [1 :: 2] return xcoords, yoOnce # todo

for the rest of the end till the end of the end of the end is provided by the professor

  intoxication = intoxication (Homer Simpson (1): f = field (drunk, place (0, 0)) coords = performTrial (500, f) print (coord) pylab.plot (Coord [0], Coord [1] Marker = '^', linestyle = ':', color = 'b') pylab.title ('Homer' 'Random Walk') pylab.xlabel ('Time') Distance from pylab.ylabel (' Distance ') pylab.show ()   

Update: Coordinate has been fixed but now I get an error:

  _xy_from_xy (self , X, y) 235 y = np.atleast_1d (y) 236 if x.shape [0]! = Y.shape [0]: - & gt; 237 increased magnifier ("X and Y should have the first dimension") 238 if x.ndim & gt; 2 or yandm & gt; 2: 23 9 value can not contain error ("x and y 2-d") Value error: The first dimension of x and y should be  

  def move (self, xc, yc): return location (self x + float (xc), self e. Float (yc) / Code>  

It does not take anything, it just gives new coordinates, besides a float should not require XC and YC castings.

If you intend to move the location of this function, then you have to add it:

  def move (self, xc, yc): self.x + = xc Self.y + = yc backspace (self.x, self.y)  

Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -