python DataCamp:用于数据科学的中级Python https://www.datacamp.com/courses/intermediate-python-for-data-scienc
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python DataCamp:用于数据科学的中级Python https://www.datacamp.com/courses/intermediate-python-for-data-scienc相关的知识,希望对你有一定的参考价值。
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(123)
all_walks = []
# Simulate random walk 500 times
for i in range(500) :
random_walk = [0]
for x in range(100) :
step = random_walk[-1]
dice = np.random.randint(1,7)
if dice <= 2:
step = max(0, step - 1)
elif dice <= 5:
step = step + 1
else:
step = step + np.random.randint(1,7)
if np.random.rand() <= 0.001 :
step = 0
random_walk.append(step)
all_walks.append(random_walk)
# Create and plot np_aw_t
np_aw_t = np.transpose(np.array(all_walks))
# Select last row from np_aw_t: ends
ends = np_aw_t[-1]
# Plot histogram of ends, display plot
plt.hist(ends)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
np.random.seed(123)
all_walks = []
# Simulate random walk 250 times
for i in range(250) :
random_walk = [0]
for x in range(100) :
step = random_walk[-1]
dice = np.random.randint(1,7)
if dice <= 2:
step = max(0, step - 1)
elif dice <= 5:
step = step + 1
else:
step = step + np.random.randint(1,7)
# Implement clumsiness
if np.random.rand() <= 0.001 :
step = 0
random_walk.append(step)
all_walks.append(random_walk)
# Create and plot np_aw_t
np_aw_t = np.transpose(np.array(all_walks))
plt.plot(np_aw_t)
plt.show()
以上是关于python DataCamp:用于数据科学的中级Python https://www.datacamp.com/courses/intermediate-python-for-data-scienc的主要内容,如果未能解决你的问题,请参考以下文章
python DataCamp:Python数据科学工具箱(第2部分)https://www.datacamp.com/courses/python-data-science-toolbox-part
数据科学中R VS Python:获胜者是...
数据科学中R VS Python:获胜者是...
markdown 来自DataCamp的“数据科学SQL简介”课程的说明
人工智能第三课:数据科学中的Python
python DataCamp:使用Python导入数据(第2部分)https://www.datacamp.com/courses/importing-data-in-python-part-2