Enrollments Open for Certification Course on Artificial Intelligence and Deep Learning by IIT Roorkee

  Apply Now

Apache Spark - Transformations - map & filter

INSTRUCTIONS
  • Map Transformation code in Scala

    val arr = 1 to 10000
    val nums = sc.parallelize(arr)
    def multiplyByTwo(x:Int):Int = x*2
    

    Write the following command in a new cell:

    multiplyByTwo(5)
    

    Write the following command in a new cell:

    var dbls = nums.map(multiplyByTwo);
    dbls.take(5)
    
  • Transformations - filter() code in Scala

    var arr = 1 to 1000
    var nums = sc.parallelize(arr)
    def isEven(x:Int):Boolean = x%2 == 0
    

    Write the following commands in a new cell:

    var evens = nums.filter(isEven)
    evens.take(3)
    

No hints are availble for this assesment

Answer is not availble for this assesment

Loading comments...