张量学习笔记 | 基础知识

本文介绍了张量的基本概念及其在MATLAB中的实现方法,包括张量积、Khatri-Rao积等高级运算,并展示了如何进行向量的外积与内积计算,以及如何将四阶张量转换为矩阵。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考资料:

1、【科普】什么是张量?_哔哩哔哩_bilibili

2、张量的直观解释_哔哩哔哩_bilibili

3、浅谈张量分解(二):张量分解的数学基础 - 知乎 (zhihu.com)

4、浅谈张量分解(四):外积、Kronecker积和张量积 - 知乎 (zhihu.com)

5、张量的一些基本操作 - 知乎 (zhihu.com)

6、张量分解 (Tensor Decomposition) - 知乎 (zhihu.com)

7、使用MATLAB快速计算Khatri-Rao积_Quino_321的博客-优快云博客

网上找了些张量的入门资料。

matlab实现基本计算:

1、张量积

 例:

程序:

C=kron(A,B)

 C =

     5     6     7    10    12    14
     8     9    10    16    18    20
    15    18    21    20    24    28
    24    27    30    32    36    40

2、Khatri-Rao积

程序:

function   kr=KR(F,G)     
		nR_F=size(F,1);        %F的行数
	    nR_G=size(G,1);      %G的行数
		mul=ones(nR_G,1);
		FF=kron(F,mul);     %通过kron函数实现对F矩阵的扩充,得到FF矩阵
		GG=repmat(G,nR_F,1);%通过repmat函数实现对G矩阵的扩充,得到GG矩阵
		kr=FF.*GG;
end

 带入A,B,执行结果:
     5    12
     7    16
     9    20
    15    24
    21    32
    27    40

3、向量的外积

>> a=[2 3 4];
>> b=[3 4 5];
>> c=cross(a,b)

c =

    -1     2    -1

4、向量的数量积(内积)

dot(x,y)

5、4阶张量展开

 程序:

X(:,:,1,1)=[1 2;3 4];
X(:,:,2,1)=[5 6;7 8];
X(:,:,1,2)=[9 10;11 12];
X(:,:,2,2)=[13 14;15 16];
X=tensor(X);
X1=tenmat(X,1)
X2=tenmat(X,2)
X3=tenmat(X,3)
X4=tenmat(X,4)

输出:

X1 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
    X1.rindices = [ 1 ] (modes of tensor corresponding to rows)
    X1.cindices = [ 2  3  4 ] (modes of tensor corresponding to columns)
    X1.data = 
             1     2     5     6     9    10    13    14
             3     4     7     8    11    12    15    16
X2 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
    X2.rindices = [ 2 ] (modes of tensor corresponding to rows)
    X2.cindices = [ 1  3  4 ] (modes of tensor corresponding to columns)
    X2.data = 
             1     3     5     7     9    11    13    15
             2     4     6     8    10    12    14    16
X3 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
    X3.rindices = [ 3 ] (modes of tensor corresponding to rows)
    X3.cindices = [ 1  2  4 ] (modes of tensor corresponding to columns)
    X3.data = 
             1     3     2     4     9    11    10    12
             5     7     6     8    13    15    14    16
X4 is a matrix corresponding to a tensor of size 2 x 2 x 2 x 2
    X4.rindices = [ 4 ] (modes of tensor corresponding to rows)
    X4.cindices = [ 1  2  3 ] (modes of tensor corresponding to columns)
    X4.data = 
             1     3     2     4     5     7     6     8
             9    11    10    12    13    15    14    16

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值