tf.matrix_diag和tf.matrix_inverse的用法(tensorflow如何生成对角矩阵和求逆矩阵)
1.tf.matrix_diag(dia):输入参数是dia,如果输入时一个向量,那就生成二维的对角矩阵,以此类推
2.tf.matrix_inverse(A):输入如果是一个矩阵,就是得到逆矩阵,依次类推,只是输入的A中的元素需要是浮点数,比如tf.float32等格式,如果是整形,就会出错哈。
例如:
矩阵(二维张量)
import tensorflow as tf;
A = [1, 2, 3]
B = tf.matrix_diag(A)
print B.eval(session=tf.Session())
B = tf.cast(B, tf.float32)
C = tf.matrix_inverse(B)
print C.eval(session=tf.Session())
输出:
[[1 0 0]
[0 2 0]
[0 0 3]]
[[ 1. 0. 0. ]
[ 0. 0.5 0. ]
[ 0. 0. 0.33333334]]
三维数组(三维张量)
import tensorflow as tf;
A = [[1, 2, 3]]
B = tf.matrix_diag(A)
print B.eval(session=tf.Session())
B = tf.cast(B, tf.float32)
C = tf.matrix_inverse(B)
print C.eval(session=tf.Session())
输出:
[[[1 0 0]
[0 2 0]
[0 0 3]]]
[[[ 1. 0. 0. ]
[ 0. 0.5 0. ]
[ 0. 0. 0.33333334]]]
---------------------
作者:UESTC_C2_403
来源:CSDN
原文:https://blog.csdn.net/UESTC_C2_403/article/details/77193595
版权声明:本文为博主z转载文章,转载请附上博文链接!
- tf.matrix_diag和tf.matrix_inverse的用法(tensorflow如何生成对角矩阵和求逆矩阵)
- TF版本问题:由于不同的TensorFlow版本之间某些函数的用法引起的错误—Jason niu
- 11、Tensorflow:tf.truncated_normal的用法详解
- TensorFlow学习笔记之tf.nn.softmax()与tf.nn.softmax_cross_entropy_with_logits的用法
- TensorFlow学习---tf生成数据的方法
- Python 如何生成矩阵
- 如何使用TensorFlow和VAE模型生成手写数字
- 【TensorFlow】tf.nn.local_response_normalization详解,lrn正则法如何计算?
- tensorflow:tf.stack的用法
- 【LaTeX】Lyx/LaTeX笔记03——用blkarray代替\bordermatrix为矩阵生成行标列标
- python如何保存矩阵,保存matrix,保存numpy.ndarray
- 生成树的计数 Matrix-Tree(矩阵树)定理
- Tensorflow:tf.flags的用法
- Tensorflow的常用矩阵生成
- Python Numpy的数组array和矩阵matrix的用法与区别
- 【TensorFlow】tf.nn.softmax_cross_entropy_with_logits的用法
- tensorflow如何读取自己的image图片(通过Queue生成batch)
- 如何用Tensorflow训练模型成pb文件(二)——基于tfrecord的读取
- tensorflow 变量生成 变量管理 tf.Variable & tf.get_variable & tf.variable_scope
- tensorflow载入数据的三种方式 之 TF生成数据的方法