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
4
votes
2 answers

Converting a complex vector to a sparse diagonal array in Julia

Trying to replicate a calculation from Matlab in Julia but am having trouble converting a single column complex array into a sparse diagonalized array for matrix multiplication. Here is the Matlab code I am trying to replicate in…
user4434674
  • 193
  • 1
  • 1
  • 8
4
votes
2 answers

Convert a column vector into a extended diagonal matrix

Consider the following column vector: vec <- rbind(c(0.5),c(0.6)) I want to convert it into the following 4x4 diagonal matrix: 0.5 0 0 0 0 0.6 0 0 0 0 0.5 0 0 0 0 0.6 I know I can do it by the following code: dia <-…
Michael
  • 565
  • 4
  • 11
4
votes
5 answers

Sum along diagonal and anti-diagonal lines in 2D array - NumPy / Python

I have a np array like below: np.array([[1,0,0],[1,0,0],[0,1,0]]) output: array([[1, 0, 0], [1, 0, 0], [0, 1, 0]]) I wish to sum left diagonal and right right diagonal line elements to new array: 1) left diagonal line : out…
james
  • 643
  • 4
  • 24
4
votes
3 answers

How can I assign a value to the diagonals of a 4-D matrix using linear indexing in MATLAB?

I have a 4-D matrix A of size NxNxPxQ. How can I easily change the diagonal values to 1 for each NxN 2-D submatrix in a vectorized way?
4
votes
3 answers

Getting diagonal "stripe" from matrix in NumPy or PyTorch

I need to get the diagonal "stripe" of a matrix. Say I have a matrix of size KxN (K>N): [[ 0 1 2] [ 3 4 5] [ 6 7 8] [ 9 10 11]] From it I need to extract a diagonal stripe, in this case, a matrix MxV size that is created by truncating the…
Ivan Bilan
  • 2,379
  • 5
  • 38
  • 58
4
votes
2 answers

Diagonal Background Structure [CSS]

Currently working on a web design project for a client where I designed a multi-layered diagonal background. I solved a single diagonal with; background-color: #dbebde; background-image: -webkit-linear-gradient(120deg, #dbebde 50%, #f8f8f8…
Lars
  • 41
  • 2
4
votes
2 answers

Android layout diagonal cut

How can I cut a layout (LinearLayout or RelativeLayout) diagonally with content inside? The mockup looks like that: I tried using diagonal layout libraries like https://github.com/florent37/DiagonalLayout but I cant seem to get this cut on the…
user754730
  • 1,341
  • 5
  • 31
  • 62
4
votes
1 answer

Replace the diagonal elements of a matrix with sum of other elements in the row in Python

import pandas as pd import numpy as np rates=(pd.read_excel("C:\Anaconda3\RateMatrix.xlsx", sheetname="Pu239Test", skiprows=0)).as_matrix() #read the matrix values from excel spreadsheet, and converts the values to a matrix rates is a 22 x 22…
DPdl
  • 723
  • 7
  • 23
4
votes
2 answers

Extract diagonals from a distance matrix in R

I would like to know how can I extract the values of the first diagonal from a distance matrix. For example: > mymatrix [,1] [,2] [1,] 1 2 [2,] 3 4 [3,] 6 4 [4,] 8 6 > dist(mymatrix) 1 2 3 2…
pateto777
  • 249
  • 1
  • 11
4
votes
1 answer

Outer function in R for upper triangular matrix

I have this code currently s1=seq(0,10,length.out=3) s2=seq(0,10,length.out=3) d=outer(s1,s2,`-`) I=outer(s1,s2,`==`) However I only want the upper triangular of d and I so I am currently doing d=d[upper.tri(d,diag=T)] I=I[upper.tri(I,diag=T)] Is…
raK1
  • 519
  • 1
  • 4
  • 13
4
votes
3 answers

Multiple constant to a matrix and convert them into block diagonal matrix in matlab

I have a1 a2 a3. They are constants. I have a matrix A. What I want to do is to get a1*A, a2*A, a3*A three matrices. Then I want transfer them into a diagonal block matrix. For three constants case, this is easy. I can let b1 = a1*A, b2=a2*A,…
aaa
  • 251
  • 3
  • 11
4
votes
2 answers

Extended block diagonal matrix in Matlab

I know that to generate a block-diagonal matrix in Matlab the command blkdiag generates such a matrix: Now I am faced with generating the same block-diagonal matrix, but with also matrix elements B_1, B_2,..., B_{n-1} on the upper diagonal, zeros…
titus.andronicus
  • 517
  • 1
  • 7
  • 19
4
votes
1 answer

NumPy - Sum of the elements on the secondary diagnoal of a 2D matrix

How can I get the sum of the elements on the secondary diagonal of a matrix? numpy.trace seems to only return main diagonals, and numpy.diagonal doesn't seem to help out with secondary diagonal either.
confused00
  • 2,556
  • 21
  • 39
4
votes
1 answer

Diagonal line across view

Based on some condition, I have to diagonally cut the list cell. For this I have made diagonal drawable image using this code: diagonal_line.xml
seema
  • 991
  • 1
  • 13
  • 27
4
votes
4 answers

Obtaining opposite diagonal of a matrix in Matlab

Let A be an matrix of size [n,n]. If I want to extract its diagonal, I do diag(A). Actually, I want the opposite diagonal, which would be [A(n,1),A(n-1,2),A(n-2,3),...]. One way to do this is via diag(flipud(A)). However, flipud(A) is quite…
Alex R.
  • 1,397
  • 3
  • 18
  • 33