【发布时间】:2019-12-16 13:04:58
【问题描述】:
在这段代码中,我生成了随机数,然后获取该数字的概率并使用直方图完成。但现在我想在 mapreduce 中运行这段代码。如何创建 mapper.py 和 reducer.py ?
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
from collections import Counter
def my_funct():
#Random Number Generating
x = np.random.randint(low=1, high=100, size=100000)
#np.random.seed(1223) # fixing the seed
counts = Counter(x)
total = sum(counts.values())
d1 = {k:v/total for k,v in counts.items()}
grad = d1.keys()
prob = d1.values()
print(str(grad))
print(str(prob))
#bins = 20
plt.hist(prob,bins=20, normed=1, facecolor='blue', alpha=0.5)
#plt.plot(bins, hist, 'r--')
plt.xlabel('Probability')
plt.ylabel('Number Of Students')
plt.title('Histogram of Students Grade')
plt.subplots_adjust(left=0.15)
plt.show()
#calling the function twice
my_funct()
#my_funct()
【问题讨论】:
-
你试过什么?这是一个相当广泛的问题。
-
@DennisJaheruddin 我想在 mapreduce 中使用此代码。
标签: python python-3.x hadoop google-cloud-platform mapreduce