what is tf data dataset reduce 28 29

Solutions on MaxInterview for what is tf data dataset reduce 28 29 by the best coders in the world

showing results for - "what is tf data dataset reduce 28 29"
Giacomo
26 Mar 2016
1# import tensorflow 
2import tensorflow as tf 
3  
4# using tf.data.Dataset.reduce() method 
5data = tf.data.Dataset.from_tensor_slices([1, 2, 3, 4, 5]) 
6  
7print(data.reduce(0, lambda x, y: x + y).numpy())
8# it return the summation of all element
9# 0 + (1+2+3+4+5)
10>> 15
11# if we use 1 instead of 0 then after summation of all array 
12# we also sum this extra 1 , so the result will be ---
13print(data.reduce(1, lambda x, y: x + y).numpy())
14# 1+(1+2+3+4+5)
15>>16
16# import tensorflow 
17import tensorflow as tf 
18  
19# using tf.data.Dataset.reduce() method 
20data = tf.data.Dataset.from_tensor_slices([[5, 10], [3, 6]]) 
21  
22print(data.reduce(0, lambda x, y: x * y).numpy())
23# [5*3*0 10*6*0]
24>>[0 0]
25print(data.reduce(1, lambda x, y: x * y).numpy())
26# [5*3*1 10*6*1]
27>>[15 60]
28# so what about this example?
29print(data.reduce(2, lambda x, y: x * y).numpy())
30# as you expect!!
31# [5*3*2 10*6*2]
32>>[30 120]