What do you want to save?
Add Code snippet
New code examples
-
Python 2022-02-22 21:35:11
Aggregate the elements of each partition, and then the results for all the partitions
#Aggregate the elements of each partition, and then the results for all the partitions seqOp = (lambda x, y: (x[0] + y, x[1] + 1)) combOp = (lambda x, y: (x[0] + y[0], x[1], y[1])) sc.parallelize([1, 2, 3, 4]).aggregate((0, 0), seqOp, combOp) # (10, 4) s... Add solution -
Python 2021-10-29 08:40:40
what is tf.data.dataset.reduce()
# import tensorflow import tensorflow as tf # using tf.data.Dataset.reduce() method data = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4, 5]) print(data.reduce(0, lambda x, y: x + y).numpy()) # it return the summation of all element # 0 + (1+2+... Add solution -
Python 2021-10-11 14:51:04
only keep few key value from dict
>>> dict_filter = lambda x, y: dict([ (i,x[i]) for i in x if i in set(y) ]) >>> large_dict = {"a":1,"b":2,"c":3,"d":4} >>> new_dict_keys = ("c","d") >>> small_... Add solution