# Invert a matrix from a 4D array : equivalence or difference with indexes

• Python

## Summary:

I am looking for help about the manipulation in a formula of the inversion of matrixes from a 4D array and the interpretation of a factor which is actually a matrix of 100x100 size in this formula.

## Main Question or Discussion Point

I have a 4D array of dimension ##100\text{x}100\text{x}3\text{x}3##. I am working with `Python Numpy. This 4D array is used since I want to manipulate 2D array of dimensions ##100\text{x}100## for the following equation (it allows to compute the ##(i,j)## element ##F_{ij}## of Fisher matrix) :

##F_{ij} = \sum_{XY}\,\int\,\dfrac{V_{0}\,\text{d}^3 k}{(2\pi)^{3}}\,\bigg(\dfrac{\partial P_{\text{obs,X}}}{\partial p_{i}}\bigg)\,(C^{-1})_{XY}\,\bigg(\dfrac{\partial P_{\text{obs,Y}}}{\partial p_{j}}\bigg)\quad(1) ##

##X## and ##Y## vary between ##1,2,3##.
The derivatives ##\bigg(\dfrac{\partial P_{\text{obs,X}}}{\partial p_{i}}\bigg)## and ##\bigg(\dfrac{\partial P_{\text{obs,X}}}{\partial p_{j}}\bigg)## are discrete arrays of dimension ##100\text{x}100##.

First I compute a "Covariance matrix" ##C## of dimension ##100\text{x}100## for each ##X## and ##Y##. So I have a 4D array for ##C##.

1) Now, I have an issue about the interpretation of the term ##(C^{-1})_{XY}##.

For the moment, what I do is to compute a 2D array of matrix ##3\text{x}3## (so a 2D array of ##10000## elements with a matrix ##3\text{x}3## for each element of this 2D array).

Then, after this, I invert the ##10000## matrixes ##3\text{x}3## and I multiply by a direct dot product of ##C^{-1}## with the derivatives in parenthesis.

To compute th final value ##F_{ij}##, I do a summation on ##X## and ##Y## (i.e on ##X,Y=1,2,3##) of the 2D final grid ##100\text{x}100## and integrate it.

2) I don't know if things of this formula are well carried out. Indeed, inverting ##10000## matrixes ##3\text{x}3## is not the same thing than inverting 9 matrixes of size ##100\text{x}100##, is it ?

In all cases, I thing I have to consider the matrix ##(C^{-1})_{XY}## like a matrix of ##100\text{x}100## dimensions.

Indeed, I think ##(C^{-1})## should be a ##100\text{x}100## matrix.

But on the other side, in my code, I perform the inversion of ##10000## ##3\text{x}3## matrixes and once this computation is done, I take the 9 matrixes of ##100\text{x}100## dimension.

Is my method right ?

3) I suppose that the 2 following operations are not commutative :

invert ##10000## matrixes of ##3\text{x}3## and using 9 matrixes of ##100\text{x}100## from this inversion OR invert directly 9 matrixes of ##100\text{x}100##

It seems that I make confusions between inverting matrix and reconstruct or use again this inversion with a 4D array.

If someone could help me to interpret correctly the equation ##(1)##, especially the term ##(C^{-1})_{XY}##, in order to do the right computations.

Regards

Related Programming and Computer Science News on Phys.org
tnich
Homework Helper
No, in general inverting 10,000 3x3 matrices will not give you the same result as inverting 9 100x100 matrices. If you want to convince yourself of that, try it both ways with a 2x2x3x3 array and see if you get the same result.

Sorry, I add more details since my first post may cause confusions.

I did a little error in the equation ##(1)## on notations of Covariance factor ##C##, the right one is :

##F_{ij} = \sum_{XY}\,\int\,\dfrac{V_{0}\,\text{d}^3 k}{(2\pi)^{3}}\,\bigg(\dfrac{\partial P_{\text{obs,X}}}{\partial p_{i}}\bigg)\,C_{XY}^{-1}\,\bigg(\dfrac{\partial P_{\text{obs,Y}}}{\partial p_{j}}\bigg)\quad(1)##

What I am almost sure is that factor ##C## must have a size of ##100\text{x}100##.

I think I have 2 choices for the factor ##C_{XY}^{-1}## in the equation ##(1)## if I use a 4D dimension array for ##C_{XY}^{-1}[0:100][0:100][0:2][0:2]## , i.e with an element noted by ##C_{XY}^{-1}[\text{i}][\text{j}][\text{k}][\text{l}]## :

1) Invert for each ##(i,j)## element a matrix ##3\text{x}3##, then I take each block of ##100\text{x}100## associated to each element of matrix ##3\text{x}3## , and after multiplying each derivatives block (of size ##100\text{x}100##) by each of the ##(k,l)## elements (which varies from ##0## to ##2##) and which represent a block ##100\text{x}100## . In this case, the formula would mean a dot-to-dot product of each element ##(i,j)## of the matrix ##C_{XY}^{-1}## (of dimensions ##100\text{x}100##), by the corresponding element ##(\text{i},\text{j})## of ##X,Y## derivatives blocks (also of dimensions ##100\text{x}100##)

2) Invert for each ##(k,l)## element a matrix of size ##100\text{x}100## and multiplying with a dot product each of the 9 matrixes ##100\text{x}100## by each of the corresponding derivatives (labeled by index ##X## and ##Y##).

For the moment, a colleague has implemented the first solution 1) but I have not enough elements to confirm if that is the right method.

I have a few difficulties to explain better the 2 approaches because there is a slightly difference but results between both will never be the same, at least I think.

QUESTION 1) : What I assume also checkable is that operation 1) and 2) don't give the same ##100\text{x}100## matrix for the factor of inverted covariance ##C_{XY}^{-1}## : is it right ?

QUESTION 2) : What do you think about these 2 possible interpretations to compute ##C_{XY}^{-1}##, which one to use ?

Any help would be great because I am stuck for a long time on this issue. Regards

Last edited: