-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3DimensionRandomWalk.py
More file actions
66 lines (54 loc) · 1.63 KB
/
3DimensionRandomWalk.py
File metadata and controls
66 lines (54 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Dec 16 15:03:03 2022
@author: fabian
"""
import random as rd
import numpy
import plotly.graph_objects as go
import plotly.io as pio
pio.renderers.default = 'browser'
rd.seed(42)
np = 50000
ns = 10
NORTH = 1; SOUTH = 2; WEST = 3; EAST = 4; IN = 5; OUT = 6
def singleStep():
position = numpy.zeros(shape=(3,), dtype=int)
currentStep = rd.randint(1, 6 + 1)
position[0] += numpy.where(currentStep == NORTH, 1, 0)
position[0] -= numpy.where(currentStep == SOUTH, 1, 0)
position[1] += numpy.where(currentStep == EAST, 1, 0)
position[1] -= numpy.where(currentStep == WEST, 1, 0)
position[2] += numpy.where(currentStep == OUT, 1, 0)
position[2] -= numpy.where(currentStep == IN, 1, 0)
return position
def walkSteps(numPart=1, numstep=100):
positionsArray = numpy.zeros(shape=(numstep+1, 3), dtype=int)
for step in numpy.arange(numstep):
positionsArray[step+1, ] = positionsArray[step, ] + singleStep()
tuple = (positionsArray, numstep)
return tuple
def drawWalk(tuple):
positionsArray = tuple[0]
fig = go.Figure(data=go.Scatter3d(
x=positionsArray[:, 0],
y=positionsArray[:, 1],
z=positionsArray[:, 2],
mode='markers',
name='Randomwalk in 2 Dimensions',
marker=dict(
color=numpy.arange(tuple[1]),
size=5,
colorscale='Greens',
showscale=True),
line=dict(
color='darkblue',
width=2
)
))
fig.show()
def main():
drawWalk(walkSteps(1, 500000))
if __name__ == "__main__":
main()