mask = tf.placeholder(tf.bool, shape=(n, n))
A = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
npmask = np.triu(np.ones((n, n), dtype=np.bool_), 1)
A_upper_triangular = tf.boolean_mask(A, mask)
print(sess.run(A_upper_triangular, feed_dict={mask: npmask}))
Convert the strictly upper triangular part of a matrix into an array in Tensorflow