我如何在我的 Mapper 和 Reducer 中使用此代码?我想要 运行 这个代码在 Google 集群中

How can i use this code in my Mapper and Reducer ? i want run this code in Google cluster

在此代码中,我生成了随机数,然后计算该数字的概率并使用直方图进行最终确定。但现在我想 运行 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()

您不能在 mapreduce 中使用 matplotlib。它没有显示结果的 GUI