Selecting diagonal elements from a matrix to make a vector

In summary, the person is looking for an operation that can filter out only the diagonal elements of a 2-tensor and transform it into a 1-tensor. They mention using tensor contraction, but note that the resulting object is not a vector and does not transform correctly.
  • #1
MasterD
13
0
Hi,

I am looking for a certain operation that makes a 1 tensor from a 2 tensor by filtering out only the diagonal elements.

For instance,

(f1g1 f1g2 f1g3)
(f2g1 f2g2 f2g3)
(f3g1 f3g2 f3g3)

becomes

(f1g1)
(f2g2)
(f3g3)

after a certain operation.

What operation could I use?

Thanks a million for the one who can help me out here.

Dirk
 
Physics news on Phys.org
  • #2
I don't think the resulting object is a 1-tensor. How would it transform?

If all you want is the SUM of those elements, then you can do simple tensor contraction: Tii. To make a 1x3 object out of the diagonal elements, you could write (no summation convention):

[tex]\sum_i T^{ii} \vec e_i[/tex]

But this object is NOT a vector; it doesn't transform correctly.
 

Related to Selecting diagonal elements from a matrix to make a vector

1. How do I select diagonal elements from a matrix to make a vector?

To select diagonal elements from a matrix, you can use the function diag in most programming languages. This function will return a vector containing the diagonal elements of the matrix.

2. Can I select only a specific diagonal from a matrix?

Yes, you can select a specific diagonal from a matrix by specifying the offset from the main diagonal. For example, the main diagonal has an offset of 0, the diagonal above it has an offset of 1, and the diagonal below it has an offset of -1.

3. What if my matrix is not square?

If your matrix is not square, meaning it does not have an equal number of rows and columns, you can still select diagonal elements to make a vector. However, the resulting vector will have a length equal to the smaller dimension of the matrix.

4. Can I select diagonal elements from a non-numeric matrix?

Yes, you can also select diagonal elements from a non-numeric matrix, such as a matrix containing strings or characters. The resulting vector will contain the diagonal elements in the same order as they appear in the matrix.

5. Is there a faster way to select diagonal elements from a large matrix?

Yes, there are methods and algorithms specifically designed for selecting diagonal elements from large matrices. One example is the extract_diag function in the LAPACK library, which is optimized for efficiency and can handle very large matrices.

Similar threads

  • Set Theory, Logic, Probability, Statistics
Replies
6
Views
1K
Replies
24
Views
1K
Replies
3
Views
1K
  • Precalculus Mathematics Homework Help
Replies
32
Views
961
  • Set Theory, Logic, Probability, Statistics
Replies
11
Views
2K
  • Special and General Relativity
Replies
1
Views
583
Replies
9
Views
1K
  • Calculus and Beyond Homework Help
Replies
5
Views
5K
  • Calculus and Beyond Homework Help
Replies
12
Views
2K
Replies
1
Views
9K
Back
Top