# Unfold a tensor into a matrix to do inversion/pseudoinversion?

**URL:** <https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175>\
**Category:** Questions\
**Tags:** algebra\
**Created:** [May 28, 2021, 4:26pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175 "2021-05-28T16:26:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![silvaalberto](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/silvaalberto/32/15417_2.png) [@silvaalberto](https://community.wolfram.com/u/silvaalberto)\
**Post date:** [May 28, 2021, 4:26pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175/1 "2021-05-28T16:26:50Z")

</div>

Dear Wolfram Community:

I have been trying without success in the last week to do some tensor operations on arrays (like the array example at the end). The tensor operations tried include dot product and especially **inverse/pseudoinverse**. The (pseudo)inverses cannot be done just applying the built-in function into the array, as they are designed just for matrices.

At first I was worried that such operations simply are undefined for arrays other than matrices. Then I found some papers suggesting the following procedure:

1. Do something called “unfolding” to turn the IJK tensor into a (m,n) matrix

2. Invert the matrix

3. Do the inverse operation “fold” to obtain the inverted tensor from the inverted matrix

Unfortunately the notation used for the mapping called “fold” and “unfold” is given by the following, cryptic formulas (taken from Kolda(2006)):

 ![kolda2006_OP_1_CP_.png](https://global.discourse-cdn.com/wolfram/original/3X/7/f/7f25c9a369514a378b176384f0d2f5e6d3d46e6f.png)

 ![kolda2006_OP_2_CP_.png](https://global.discourse-cdn.com/wolfram/original/3X/2/0/205c0f68950ef63778e781f663ce4d030f438052.png)

Finally, a code is given, unfortunately in MATLAB and not in Mathematica:

 ![kolda2006_OP_3_CP_.png](https://global.discourse-cdn.com/wolfram/original/3X/6/c/6c4de1b28eaa428ed63d417609659f8916e6d8ed.png)

Do someone knows how to “translate” the cryptic formulas of Kolda (2006) or her MATLAB code into a Wolfram Mathematica code?

Thank you in advance.

APPENDIX:

1. References:

2. Code of the example array I wish to invert:

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [May 28, 2021, 4:48pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175/2 "2021-05-28T16:48:35Z")

</div>

May be you find some ideas here

> [@Invert a 2x2 matrix with 2x2 matrix elements?](https://wolfram.discourse.group/t/13875/1):
>
> If this is my matrix a as follows: a00 a01 a10 a11 Element a00 would be comprised of a matrix b as follows: b00 b01 b10 b11 And so on ... I want to solve my A matrix using Mathematica algorithm. Thanks for your help. Stan

(the link may be not complete)

Especially in the notebooks at the end

---

<div class="post-metadata">

**Author:** ![silvaalberto](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/silvaalberto/32/15417_2.png) [@silvaalberto](https://community.wolfram.com/u/silvaalberto)\
**Post date:** [May 28, 2021, 5:00pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175/3 "2021-05-28T17:00:58Z")

</div>

Thank you for your early answer, but the link is not working.

---

<div class="post-metadata">

**Author:** ![danielsanderhoffmann](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/danielsanderhoffmann/32/15670_2.png) [@danielsanderhoffmann](https://community.wolfram.com/u/danielsanderhoffmann)\
**Post date:** [May 28, 2021, 6:21pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175/4 "2021-05-28T18:21:08Z")

</div>

Actually it is working, Alberto. Simply use copy and paste.

---

<div class="post-metadata">

**Author:** ![silvaalberto](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/silvaalberto/32/15417_2.png) [@silvaalberto](https://community.wolfram.com/u/silvaalberto)\
**Post date:** [May 28, 2021, 8:49pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175/5 "2021-05-28T20:49:14Z")

</div>

Done, thank you for the clue.

---

<div class="post-metadata">

**Author:** ![silvaalberto](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/silvaalberto/32/15417_2.png) [@silvaalberto](https://community.wolfram.com/u/silvaalberto)\
**Post date:** [May 28, 2021, 9:01pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175/6 "2021-05-28T21:01:35Z")

</div>

I just found the relevant community group.

The attached notebooks and papers there are very interesting.  
Where is better to continue the discussion with additional questions (if needed)?

1. Here

2. At the discussion you linked: [Stan Gianzero question && answers](https://wolfram.discourse.group/t/13875/1)

3. At the related review discussion: [Inverse of a (m,m)-Matrix whose elements are (n,n)-Matrices](https://wolfram.discourse.group/t/14429/1)

Best regards,

Alberto

---

<div class="post-metadata">

**Author:** ![hdolhaine](https://yyz1.discourse-cdn.com/wolfram/user_avatar/community.wolfram.com/hdolhaine/32/35924_2.png) [@hdolhaine](https://community.wolfram.com/u/hdolhaine)\
**Post date:** [May 28, 2021, 11:02pm UTC](https://community.wolfram.com/t/unfold-a-tensor-into-a-matrix-to-do-inversion-pseudoinversion/18175/7 "2021-05-28T23:02:37Z")

</div>

1. Here
