当前位置:网站首页>Tensorflow Einstein function
Tensorflow Einstein function
2022-07-24 06:57:00 【Live up to your youth】
The function prototype
tf.einsum(
equation, *inputs, **kwargs
)
Function description
Used to implement tensorflow Dot product of tensor in 、 Exoproduct 、 device 、 Matrix multiplication and so on ,einsum Is an expression of these operations , Elegant ways including complex tensor operations , Basically , You can put einsum As a domain specific language . Once you understand and can use einsum, In addition to the benefits of not having to remember and frequently looking for specific library functions , You can also write faster and more compact 、 Efficient code .
such as , Two tensors A、B Multiply , Get the matrix C, The formula is as follows :

With corresponding einsum Expressed as :
ij,jk->ik
Parameters equation Indicates the corresponding einsum Notation , Is a string ; Parameters *inputs Represents multiple tensors of input , Shape should be consistent with equation Corresponding to in .
Function USES
1、 Matrix dot product ,c = sum_i a[i]*b[i]
>>> a = tf.constant([1, 2, 3, 4])
>>> b = tf.constant([2, 2, 2, 2])
>>> tf.einsum("i,i->", a, b)
<tf.Tensor: shape=(), dtype=int32, numpy=20>
2、 Matrix multiplication ,c[i, k] = sum_j a[i, j]*b[j, k]
>>> a = tf.ones([2, 2])
>>> b = tf.ones([2, 2])
>>> tf.einsum("ij,jk->ik", a, b)
<tf.Tensor: shape=(2, 2), dtype=float32, numpy=
array([[2., 2.],
[2., 2.]], dtype=float32)>
3、 Matrix transposition , b[j, i] = a[i, j]
>>> a = tf.constant([[1, 2], [3, 4]])
>>>> a
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[1, 2],
[3, 4]])>
>>> tf.einsum("ij->ji", a)
<tf.Tensor: shape=(2, 2), dtype=int32, numpy=
array([[1, 3],
[2, 4]])>
4、 Get diagonal elements of matrix
>>> a = tf.linalg.band_part(tf.ones((3, 3)), 0, 0)
>>> a
<tf.Tensor: shape=(3, 3), dtype=float32, numpy=
array([[1., 0., 0.],
[0., 1., 0.],
[0., 0., 1.]], dtype=float32)>
>>> tf.einsum("ii->i", a)
<tf.Tensor: shape=(3,), dtype=float32, numpy=array([1., 1., 1.], dtype=float32)>
边栏推荐
- Three level classification / menu query tree structure
- tensorflow scatter_nd函数
- [jquery custom plug-in] 1 custom cache plug-in -jquerycache
- 创建WPF项目
- [learning notes] possible reasons and optimization methods for white screen on Web pages
- Redis special data type Geo
- Don't compare with anyone, just be yourself
- [audio decoding chip] Application of vs1503 audio decoding chip
- [lvgl (5)] label usage
- 不要太在意别人对你的看法
猜你喜欢

Three level classification / menu query tree structure

【学习笔记】网页出现白屏可能的原因与优化方法

安装snownlp包过程出现Requirement already satisfied:及Read timed out.问题解决方法

三级分类/菜单的查询——树形结构

Special effects - bubble tailing occurs when the mouse moves
![[learning notes] Web page rendering process](/img/29/3f419f5851dac1194a94a59635846f.png)
[learning notes] Web page rendering process
![[wechat applet] understand conditional rendering, list rendering and wxss template style](/img/97/cb78efcbcfe1a598da87751c482a98.png)
[wechat applet] understand conditional rendering, list rendering and wxss template style
![[lvgl (3)]](/img/d3/1e2bad232f29c6c75ff163a6c0f378.png)
[lvgl (3)]
![[media controller] open source project learning notes (based on Arduino micro development board)](/img/08/39ed97437f235806c6d4415f53c47b.png)
[media controller] open source project learning notes (based on Arduino micro development board)

Detailed analysis of the process (life cycle) of class loading
随机推荐
Special effects - click with the mouse and the fireworks will burst
【微信小程序】一文搞懂条件渲染、列表渲染以及wxss模板样式
在线问题反馈模块实战(十二):实现图片删除功能
Redis数据类型-列表List
SparkSQL核心使用,220724,
ADB interaction - kill the ugly default shell interface
HashSet to array
String question
项目问题积累
渗透学习-SQL注入篇-靶场篇-安全狗的安装与绕过实验(后续还会更新)
Redis.conf details
永远不要迷失自我!
【学习笔记】从汇编看 a+++a与 a+a++的区别
xavier_normal_ 初始化测试
MGR_mysqlsh_keepalive高可用架构部署文档
[lvgl layout] grid layout
MapReduce (I)
Don't care too much about what others think of you
Breadth first search (template use)
STM32基于hal库的adc以DMA的多通道采样以及所遇问题解决