当前位置:网站首页>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)>
边栏推荐
- Kubernetes rapid installation
- [jQuery自定义插件] 1 自定义缓存插件-jQueryCache
- Special effects - when the mouse moves, stars appear to trail
- 华为专家自述:如何成为优秀的工程师
- tensorflow scatter_nd函数
- Special effects - when the mouse moves, there will be a custom expression trail
- JS and TS learning summary
- String question
- Redis.conf详解
- postgresql 日期处理函数用法
猜你喜欢

Directory and file management

Redis special data type hyperloglog
![[audio decoding chip] Application of vs1503 audio decoding chip](/img/ee/0d5f95fba647592cc95f1e9f410bc9.png)
[audio decoding chip] Application of vs1503 audio decoding chip
![[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)

Metaltc5.0 realizes webrtc version IPC of Junzheng pure C

Record the pits encountered in the deserialization of phpserializer tool class

(笔记整理未完成)【图论:求单源最短路径】

MySQL gets the self incrementing line mark (different from MySQL version)

Mac解决 Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)问题

极客星球丨 字节跳动一站式数据治理解决方案及平台架构
随机推荐
[lvgl] [stage summary 1]
Experiment: creation, expansion, and deletion of LVM logical volumes
STM32基于hal库的adc以DMA的多通道采样以及所遇问题解决
Redis特殊数据类型-HyperLogLog
Practice of online problem feedback module (12): realize image deletion function
Redis.conf details
Don't care too much about others' eyes, it will erase your glory
Redis特殊数据类型-BitMap
[wechat applet] understand conditional rendering, list rendering and wxss template style
STM32外部中断(寄存器版本)
(static, dynamic, file) three versions of address book
[jQuery自定义插件] 1 自定义缓存插件-jQueryCache
Redis data type - list list
[media controller] open source project learning notes (based on Arduino micro development board)
Mac解决 Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)问题
(笔记整理未完成)【图论:求单源最短路径】
别太在意别人的眼光,那会抹杀你的光彩
SparkSQL核心使用,220724,
Gangster escape 3
不去和谁比较,只需做好自己