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
2
votes
1 answer

Retrieve upper triangular elements of a matrix and order them by off-diagonal order

I have a matrix (dimension can be large) and want to retrieve all upper triangular elements then order them by off-diagonal order. For example, given A = matrix(1:25, 5, 5), the output res is res = c( c(6,12,18,24), c(11,17,23), c(16,22), c(21) ) ##…
yliueagle
  • 1,191
  • 1
  • 7
  • 22
2
votes
1 answer

Creating a diagonal line of stars that the user has defined in C++

I am having to write some code that needs to create a diagonal line of asterisks. I know how to write code that outputs a triangle: cout<<"What size of stars would you like to draw? "; cin>>star; int space; for(int i = 1, k = 0; i <= star; I++, k =…
Trev.Drumm
  • 15
  • 2
  • 7
2
votes
2 answers

how to get the diagonal components of numpy 3-D array?

I have an 3-D array like a = np.array( [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] ) and I want to get the diagonal component from this array, I mean, >> np.array([a[i,i,:] for i in range(min(a.shape[0], a.shape[1]))]) array([[1,…
seekworser
  • 23
  • 1
  • 4
2
votes
1 answer

Creating representative diagonal matrix: javascript

I am trying to create a matrix to represent the diagonal options in a scalable board game where the number of rows and number of columns are defined by the player. The objective of the game is to beat your opponent to connect a string of your piece…
dollarhino
  • 45
  • 1
  • 4
2
votes
1 answer

verify Eight Queens solution via sums of diagonal elements in a 2D array

I'm working on an assignment concerning the Eight Queen Puzzle in chess. The exercise is as follows: Given an arrangement of the 8 queens on the chessboard, write a C program which will evaluate the arrangement and inform the user if this…
2
votes
2 answers

spdiags() function not working as expected in Python

In Matlab/Octave, spdiags([-8037.500 50.000 -12.500], 0:2, 1, 51) gives following output: (1, 1) -> -8037.5 (1, 2) -> 50 (1, 3) -> -12.500 However, when I use the following in Python, it does not produce a similar result as in…
user11
  • 191
  • 1
  • 3
  • 11
2
votes
2 answers

Custom view clickable area overlap

I have a diagonal shaped imageview. When i clicked the imageview it doesn't respect the clipped area and perform clicking on the transparent area aswell. How can i make only non transparent area or shape clickable? You can see the view's source…
Fatih Santalu
  • 4,641
  • 2
  • 17
  • 34
2
votes
2 answers

How to calculate diagonal of a matrix product in Tensorflow?

I have two matrices A and B of shape (M, N) with very large M and small N. I would like to multiply them and then take diagonal of a result: C = tf.matmul(A, B) D = tf.diag_part(C) Unfortunately, this requires of creating of very big (M, M) matrix,…
Dims
  • 47,675
  • 117
  • 331
  • 600
2
votes
2 answers

How to sort characters in a string diagonally

im splitting a string by the square number of his length.. String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; int a = alphabet.length(); int b = (int)Math.round(Math.sqrt(a)); System.out.println(java.util.Arrays.toString(splitter(key, b))); //…
2
votes
1 answer

Finding a diagonal boundary in a one dimensional array

I have a chess board array that looks like this: 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 Now…
Joshua M. Moore
  • 381
  • 6
  • 20
2
votes
3 answers

How can I get counterdiagonals of a matrix and concatenate them?

Short Version How can I do concatMap in MATLAB? I'm trying to build a single vector from a series of smaller, differently sized vectors. I know I can do: result = []; for i=1:N result = [result nextPart(i)]; end but that has a serious speed…
So8res
  • 9,856
  • 9
  • 56
  • 86
2
votes
2 answers

Edge detection at a certain degree using canny method

I am using MATLAB. I want to use canny method for edge detection. But I need the edges that are diagonal or the edges that are only on 40 to 50 degree angle. how can i do that?
2
votes
1 answer

How to rediagonalize the diagonal of a matrix in MATLAB?

I have a 5x5 matrix, V1, with values and a classification in both the first row and first column. If you wanted to, you could think of sectors in an economy that have a classification. The first two sectors have a 3-digit classification, the last…
P.W.
  • 21
  • 1
2
votes
1 answer

Return diagonal elements of scipy sparse matrix

Given a scipy.sparse.csr.csr_matrix, is there a quick way to return the elements on the diagonal? The reason I would like to do this is to compute inv(D) A, where D is a diagonal matrix whose diagonal entries agree with A (A is my sparse matrix,…
user1493321
2
votes
1 answer

Buttons and divs with diagonal sides (CSS)

I'm trying to make buttons and divs with diagonal sides. When I make a medium sized box (300px x 200px) it kinda works (I used :after and a rotated div), but for smaller elements like the menu and buttons it doesn't align properly. I've been stuck…
ZoFem
  • 309
  • 4
  • 20