我试图将矩阵的严格上三角形部分转换为Tensorflow中的数组.这是一个例子:
输入:
[[1, 2, 3],
[4, 5, 6],
[7, 8, 9]]
Run Code Online (Sandbox Code Playgroud)
输出:
[2, 3, 6]
Run Code Online (Sandbox Code Playgroud)
我尝试了以下代码,但它不起作用(报告错误):
def upper_triangular_to_array(A):
mask = tf.matrix_band_part(tf.ones_like(A, dtype=tf.bool), 0, -1)
return tf.boolean_mask(A, mask)
Run Code Online (Sandbox Code Playgroud)
谢谢!