Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. import tensorflow as tf
  2. import numpy as np
  3. import os
  4.  
  5.  
  6. # My CPU supports lower level instructions so this line is required
  7.  
  8. os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
  9.  
  10.  
  11. np.random.seed(100)
  12. array = np.random.randint(1, 11, size=(6, 10))
  13. all_num = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]*6)
  14. all_ones = np.ones((1, 10))
  15.  
  16. tensor = tf.Variable(initial_value=array, dtype=tf.int32)
  17. add = tf.Variable(initial_value=all_num, dtype=tf.int32)
  18.  
  19. modified = tf.concat([tensor, add], 1)
  20.  
  21. modified = tf.sort(modified)
  22.  
  23. count = []
  24.  
  25. for row in tf.unstack(modified):
  26.     out, idx, count_temp = tf.unique_with_counts(row)
  27.     count.append(count_temp)
  28.  
  29.  
  30. init = tf.global_variables_initializer()
  31.  
  32.  
  33. with tf.Session() as sess:
  34.     sess.run(init)
  35.     for row in count:
  36.         print(sess.run(row - all_ones))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement