Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tensorflow as tf
- import numpy as np
- import os
- # My CPU supports lower level instructions so this line is required
- os.environ['TF_CPP_MIN_LOG_LEVEL'] = '2'
- np.random.seed(100)
- array = np.random.randint(1, 11, size=(6, 10))
- all_num = np.array([[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], ]*6)
- all_ones = np.ones((1, 10))
- tensor = tf.Variable(initial_value=array, dtype=tf.int32)
- add = tf.Variable(initial_value=all_num, dtype=tf.int32)
- modified = tf.concat([tensor, add], 1)
- modified = tf.sort(modified)
- count = []
- for row in tf.unstack(modified):
- out, idx, count_temp = tf.unique_with_counts(row)
- count.append(count_temp)
- init = tf.global_variables_initializer()
- with tf.Session() as sess:
- sess.run(init)
- for row in count:
- print(sess.run(row - all_ones))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement