Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python random walk

# Python code for 1-D random walk.
import random
import numpy as np
import matplotlib.pyplot as plt
 
# Probability to move up or down
prob = [0.05, 0.95] 
 
# statically defining the starting position
start = 2 
positions = [start]
 
# creating the random points
rr = np.random.random(1000)
downp = rr < prob[0]
upp = rr > prob[1]
 
 
for idownp, iupp in zip(downp, upp):
    down = idownp and positions[-1] > 1
    up = iupp and positions[-1] < 4
    positions.append(positions[-1] - down + up)
 
# plotting down the graph of the random walk in 1D
plt.plot(positions)
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: how to add csrf token in python requests 
Python :: loading in pyqt5 
Python :: instagram python bot 
Python :: end in print python 
Python :: install older version of python 
Python :: fill missing values with 0 
Python :: make sns heatmap colorbar larger 
Python :: Python Remove all occurrences of a character from a string 
Python :: how to append two numpy arrays 
Python :: install chrome driver python 
Python :: sns how to change color if negative or positive 
Python :: import discord 
Python :: bs4 innerhtml 
Python :: python get local ipv4 
Python :: coloring text in python 
Python :: rgb color python 
Python :: append extend python 
Python :: python create a dictionary of integers 
Python :: python train test val split 
Python :: python seaborn color map 
Python :: how to learn python 
Python :: python count same number in list 
Python :: Matplotlib inside Jupyter | Jupyter generate graphs. 
Python :: python string cut right 
Python :: python help 
Python :: python access key in dictionary 
Python :: openai gym random action 
Python :: python join list 
Python :: install python 3.8 on wsl 
Python :: how to check if value is in list python 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =