# 1. Garage Parking,Close to Public TransportationConsider. Here,

rddOne = sc.parallelize(listOne).map(lambda element :(element,1))
#Output of above line would be a new RDD containing elements (1,1),(1,2),(1,3),(1,4),(1,5),(1,5) For each input function, one element is returned

rddTwo = sc.parallelize(listOne).map(lambda element :(x+element) for x in 1,2,3)
# Output of above line would be new RDD having following elements : 2, 3, 4, 3, 4, 5, 4, 5, 6, 5, 6, 7, 6, 7, 8, 6, 7, 8. For each element it is returning a list and not key value pair
RDD Actions:listOne = 1,2,3,4,5,5
rddOne = sc.parallelize(listOne).count()
#Will return the number of elements in rddOne (integer) which in this case is 6

We Will Write a Custom Essay Specifically
For You For Only \$13.90/page!

order now

result = sc.parallelize(listOne).map(lambda element :(element,1)).collect()
#The value of result here is a list containing all elements in rdd (1,1),(1,2),(1,3),(1,4),(1,5),(1,5). It transfers the data from executor to the driver.
17.listOne = 1,2,3,4,5,6,7,8,9,10

dictionary = {1:0, 2:1}

def nthValue(i):
if i in dictionary:
return dictionaryi
else :
value = nthValue(i-1) + nthValue(i-2)
dictionaryi = value
return value

rdd = sc.parallelize(listOne).map(lambda num : (num, nthValue(num)))

print(rdd.values().collect())
18.  Sparse vectors are generally used when there are a lot of zeros , while dense vectors are used when there are lot of non-zero values in vectors. Vectors are is an array of numbers, suppose we have 1000 dimensional vectors which means it will be reprsented as 1,2,3….1000th value values. If many of them are zeros, it will cause wastage of storage, hence instead of that we can store it its position and value example 1 3 4 6 meaning value at 1st position is 3, value at 4th position is 6and so one. We are representing it as position and value pair.from pyspark.mllib.linalg import Vectors
#For representing vector 1,0,4,0,8

denseVector = Vectors.dense(1, 0, 4, 0, 8);

#Arguments : Length of vector, Positions at which value is present, values in the order of positions mentioend before
sparseVector = Vectors.sparse(5,0,2,4,1,4,8)
19.  No, print(a) will not print the contents of a. It will just give information about tensor a.C represents tensor got after matrix multiplication of a and b and hence will be of dimensions 3×1. Contents of the tensor are printed when we use eval() function. However for eval function to be used we need a session. So contents of c can be printed in following wayimport tensorflow as tf
sess = tf.InteractiveSession()
a = tf.constant(3, 5, 10, 11, -1, -2, dtype=tf.float32)
b = tf.constant(4, 6, dtype=tf.float32)
c = tf.matmul(a,b)
c.eval()
sess.close()

#array( 42.,
# 106.,
# -16., dtype=float32)
20. Dataflow graphs are used by TensorFlow to represent the computation so as to identify depencdecnies of operation on each other. Following are the two advantages of computational graphs :Parallelism : It helps us identify which operations in computation can be run parallel.Portability : It is possible to have data flow graph generated and saved in one language and later open it in other languageReference :  https://www.tensorflow.org/