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
87
votes
13 answers

draw diagonal lines in div background with CSS

I have a div for a preview box: .preview-content { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAGklEQVQIW2NkYGD4D8SMQAwGcAY2AbBKDBUAVuYCBQPd34sAAAAASUVORK5CYII=) repeat; width: 100%; min-height:…
Ing. Michal Hudak
  • 5,338
  • 11
  • 60
  • 91
75
votes
14 answers

Get all the diagonals in a matrix/list of lists in Python

I'm looking for a Pythonic way to get all the diagonals of a (square) matrix, represented as a list of lists. Suppose I have the following matrix: matrix = [[-2, 5, 3, 2], [ 9, -6, 5, 1], [ 3, 2, 7, 3], [-1, 8,…
BioGeek
  • 21,897
  • 23
  • 83
  • 145
43
votes
1 answer

Why is the diag function so slow? [in R 3.2.0 or earlier]

I was looking at the benchmarks in this answer, and wanted to compare them with diag (used in a different answer). Unfortunately, it seems that diag takes ages: nc <- 1e4 set.seed(1) m <- matrix(sample(letters,nc^2,replace=TRUE), ncol =…
Frank
  • 66,179
  • 8
  • 96
  • 180
23
votes
5 answers

Sum of antidiagonal of a matrix

I'm trying to sum the elements along the antidiagonal (secondary diagonal, minor diagonal) of a matrix. So, if I have a matrix m: m <- matrix(c(2, 3, 1, 4, 2, 5, 1, 3, 7), 3) m [,1] [,2] [,3] [1,] 2 4 1 [2,] 3 2 3 [3,] 1 …
Windstorm1981
  • 2,564
  • 7
  • 29
  • 57
20
votes
6 answers

NumPy k-th diagonal indices

I'd like to do arithmetics with k-th diagonal of a numpy.array. I need those indices. For example, something like: >>> a = numpy.eye(2) >>> a[numpy.diag_indices(a, k=-1)] = 5 >>> a array([[ 1., 0.], [ 5., 1.]]) Unfortunately, diag_indices…
K3---rnc
  • 6,717
  • 3
  • 31
  • 46
15
votes
3 answers

How to compute only the diagonal of a matrix product in Octave?

Is there a way in Octave to compute and store only the diagonal of a matrix product? Basically like doing: vector = diag(A*B); I don't care about any of the values of A*B except those on the diagonal. The matrix sizes are around 80k x 12 and 12 x…
Chris H
  • 6,433
  • 5
  • 33
  • 51
13
votes
3 answers

Find all n-dimensional lines and diagonals with NumPy

Using NumPy, I would like to produce a list of all lines and diagonals of an n-dimensional array with lengths of k. Take the case of the following three-dimensional array with lengths of three. array([[[ 0, 1, 2], [ 3, 4, 5], […
2Cubed
  • 3,401
  • 7
  • 23
  • 40
13
votes
3 answers

Extracting off-diagonal slice of large matrix

I've got a large nxn matrix and would like to take off-diagonal slices of varying sizes. For example: 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6 I'd like an R function which, when given the matrix and "width of diagonal…
blmoore
  • 1,487
  • 16
  • 31
10
votes
2 answers

Sum of independent diagonal in a matrix

I'm currently studying for an exam and I'm trying to deal with dynamical matrix. I've come across a problem regarding calculating the sum of every diagonal of a matrix whose values and size are chosen by the user. The intent of my program is to…
King Powa
  • 441
  • 3
  • 9
10
votes
4 answers

How to sum over diagonals of data frame

Say that I have this data frame: 1 2 3 4 100 8 12 5 14 99 1 6 4 3 98 2 5 4 11 97 5 3 7 2 In this above data frame, the values indicate counts of how many observations take on (100, 1), (99,…
bill999
  • 2,147
  • 8
  • 51
  • 103
10
votes
4 answers

Removing diagonal elements from matrix in R

How can I remove the diagonal elements (diagL) from my matrix L using R? I tried using the following: subset(L, select=-diag(L)) or subset(L, select=-c(diag(L))) but I get 0 numbers...
Titi90
  • 139
  • 2
  • 4
  • 12
10
votes
5 answers

Create diagonal border of a cell

I wonder if it is even possible creating a table with diagonal border line using css or jquery just like below: Any ideas will be appreciated.
Henry Gunawan
  • 922
  • 3
  • 18
  • 38
9
votes
5 answers

Max value per diagonal in 2d array

I have array and need max of rolling difference with dynamic window. a = np.array([8, 18, 5,15,12]) print (a) [ 8 18 5 15 12] So first I create difference by itself: b = a - a[:, None] print (b) [[ 0 10 -3 7 4] [-10 0 -13 -3 -6] [ 3 …
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
9
votes
6 answers

CSS diagonal div background

For a website I'm developing I need to include some diagonal shaped borders to a div. These are the main examples which I need to recreate. double diagonal top border, triangle shaped Now been scouting the web on how to achieve this, and my first…
Gurbii
  • 245
  • 2
  • 5
  • 15
9
votes
2 answers

two divs split with diagonal line - CSS

I am trying to get two divs to fit the full width of the page but split in half with a diagonal line. How can I achieve this with two divs through CSS? it is for a slider and needs content added to each part when finished
5kud
  • 327
  • 2
  • 6
  • 19
1
2 3
38 39