【问题标题】:How can i use this code in my Mapper and Reducer ? i want run this code in Google cluster如何在我的 Mapper 和 Reducer 中使用此代码?我想在 Google 集群中运行此代码
【发布时间】: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


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-02-17
    • 1970-01-01
    • 1970-01-01
    • 2013-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-30
    相关资源
    最近更新 更多