Questions tagged [diagonal]

Diagonal means either a diagonal matrix (usually a square matrix) in which the entries outside the main diagonal are all zero. The diagonal entries themselves may or may not be zero. Or, the values of the diagonal matrix.

Since a lot of things in programming is based on matrices doing thing horizontal or vertical is often easier then doing it diagonal. Questions dealing with these difficulties should be tagged diagonal.

Diagonal matrices occur in many areas of linear algebra. Because of the simple description of the matrix operation and eigenvalues/eigenvectors, it is always desirable to represent a given matrix or linear map by a diagonal matrix.

You probably want to add more specific tags about the technology you are using. Areas where the tag ´diagonal´ becomes relevant often drawing and animation.

584 questions
9
votes
4 answers

Create a UIView with only one diagonal side

I need to create a UIView that has the left border inclined with 45 degrees I was wondering,is there a way to acheive this programmatically? Does CATransform3D help me in this case since it’s not really a “3D rotation”? Edit Here's an image…
Odin
  • 642
  • 1
  • 9
  • 27
8
votes
2 answers

Extract sub- and superdiagonal of a matrix in R

As the title implies, how does one extract the sub- and superdiagonal of a matrix?
ego_
  • 1,409
  • 6
  • 21
  • 31
8
votes
1 answer

How to make a diagonal matrix from a vector

using LinearAlgebra; a = rand(4,1); B = diagm(a); C = Diagonal(a); The above code causes an error/(not intended) in creating a diagonal matrix. if a = [1 2 3 4] I need a matrix like: D = [1 0 0 0;0 2 0 0;0 0 3 0;0 0 0…
Vinod
  • 4,138
  • 11
  • 49
  • 65
8
votes
2 answers

I want to apply two functions one function on the block diagonal and the second function on the off-diagonal elements in the data frame

df<- data.frame(a=c(1:10), b=c(21:30),c=c(1:10), d=c(14:23),e=c(11:20),f=c(-6:-15),g=c(11:20),h=c(-14:-23),i=c(4:13),j=c(1:10)) In this data frame, I have three block-diagonal matrices which are as shown in the image below I want to apply two…
Jisika
  • 405
  • 3
  • 9
8
votes
4 answers

Replace diagonal elements with vector in PyTorch

I have been searching everywhere for something equivalent of the following to PyTorch, but I cannot find anything. L_1 = np.tril(np.random.normal(scale=1., size=(D, D)), k=0) L_1[np.diag_indices_from(L_1)] = np.exp(np.diagonal(L_1)) I guess there…
azal
  • 1,210
  • 6
  • 23
  • 43
8
votes
3 answers

Responsive diagonal lines css

I need help with setting a diagonal line in css to fit into many resolutions via mobile. Theres a div with 100% width and a diagonal line that supposed to stay in its place inside that div but every time I change the resolution of the window the…
Lilac Oren
  • 105
  • 1
  • 7
8
votes
2 answers

How to create a div with a diagonal (or angled) top line

I'm a newbie on CSS3 and all I know is self-learned, reading you guys or any other tutorials so after hours of researching and trial-error, I could really use your help :(. I'm trying to rotate JUST the top line of a div. This is what I did so…
bibifont
  • 83
  • 1
  • 1
  • 4
8
votes
4 answers

Simultaneously diagonalize matrices with numpy

I have a m × n × n numpy.ndarray of m simultaneously diagonalizable square matrices and would like to use numpy to obtain their simultaneous eigenvalues. For example, if I had from numpy import einsum, diag, array, linalg, random U =…
Anaphory
  • 6,045
  • 4
  • 37
  • 68
8
votes
3 answers

How to create dynamic diagonal line from left-bottom to right-top corner?

I've created a simple layout where I have three divs which interact. One is the logo in the middle of the screen and the other are two blocks which with jQuery are moved out of the screen. I used the skew option from CSS to apply a degree…
7
votes
4 answers

Modify Eigen matrix diagonal

I have an Eigen::MatrixXd and I need to modify the value of the elements in its diagonal. In particular I have another Eigen::MatrixXd with one single column and the same number of rows of the first matrix. I need to subtract to the diagonal of the…
Nick
  • 10,309
  • 21
  • 97
  • 201
7
votes
1 answer

Remove/set the non-zero diagonal elements of a sparse matrix in scipy

Say I would like to remove the diagonal from a scipy.sparse.csr_matrix. Is there an efficient way of doing so? I saw that in the sparsetools module there are C functions to return the diagonal. Based on other SO answers here and here my current…
Midnighter
  • 3,771
  • 2
  • 29
  • 43
6
votes
2 answers

Extracting blocks from block diagonal PyTorch tensor

I have a tensor of shape (m*n, m*n) and I want to extract a tensor of size (n, m*n) containing the m blocks of size n*n that are on the diagonal. For example: >>> a tensor([[1, 2, 0, 0], [3, 4, 0, 0], [0, 0, 5, 6], [0, 0, 7,…
nono
  • 175
  • 4
6
votes
4 answers

Delete diagonals of zero elements

I'm trying to reshape an array from its original shape, to make the elements of each row descend along a diagonal: np.random.seed(0) my_array = np.random.randint(1, 50, size=(5, 3)) array([[45, 48, 1], [ 4, 4, 40], [10, 20, 22], …
XioHu
  • 123
  • 4
6
votes
2 answers

Singular Value Decomposition (SVD) outputs a 1-D singular value array, instead of 2-D diagonal matrix [Python]

I was posting a question on similar subject, and encountered another more important question. When I apply SVD to a matrix 'A' (code below) the output I get is the expected 2-D eigenvector matrices ('U' and 'V') and an unexpected 1-D singular value…
enricw
  • 263
  • 4
  • 19
6
votes
3 answers

Python: Non diagonal elements of a matrix to 0

What is the quickest way to convert the non-diagonal elements of a square symmetrical numpy ndarray to 0?
Prgmr
  • 129
  • 4
  • 11
1
2
3
38 39