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

Is there a vectorized approach to reverse an n x m numpy array and shift the front end zeros to the back

Suppose A = np.array([1,0,2,0,0,0,0],[1,2,0,3,5,0,0],[5,6,7,0,9,5,10]) From A I'm trying to create B such that: B = np.array([2,0,1,0,0,0,0],[5,3,0,2,1,0,0],[10,5,9,0,7,6,5]) In other words B is A reversed with the leading zeros rotated to the…
phntm
  • 511
  • 2
  • 11
2
votes
1 answer

Is there a way to populate the off diagonals of a numpy array similar to numpy.fill_diagonal?

I am trying to populate the off diagonals of a numpy array with the columns of a separate array. Is there a way to do this for off diagonals similar to numpy.fill_diagonal? Suppose: A = np.zeros((4,4)) array([[0., 0., 0., 0.], [0., 0., 0.,…
phntm
  • 511
  • 2
  • 11
2
votes
2 answers

How to create a sparse diagonal matrix?

Might be a very silly question, but I cannot seem to find a proper way to create a sparse diagonal matrix in R. I've found the functions: diag.spam() spdiags() and used them with library Matrix and package spam downloaded, but R did not seem to…
Britta
  • 135
  • 1
  • 1
  • 8
2
votes
2 answers

elem function of no limit list

list comprehension haskell paar = [(a,b) | a<-[a | a<-[1..], mod a 3 == 0], b<-[b*b | b<-[1..]]] a = divisor 3 b = square The Elements must be constructed by equitable order. the test >elem (9, 9801) must be True my Error Main> elem (9, 9801)…
corium
  • 53
  • 4
2
votes
2 answers

How to compose several matrices into a big matrix diagonally in Pytorch

I have several matrices, let's say [M1,M2,M3,M4]. Each matrix has a different shape. How do I compose these matrices into one big matrix diagonally like: [[M1, 0, 0, 0] [0, M2, 0, 0] [0, 0, M2, 0] [0, 0, 0, M2]] Example: M1 = [[1,2],[2,1]] M2 =…
jon
  • 33
  • 5
2
votes
1 answer

R - transform upward diagonals to rows

I am given a matrix, data frame or data table. I would like to create a matrix with the upward/reverse diagonals as rows and the remaining cells as NA. I was able to do this. But I think, there should be an easier and simpler solution. So any…
Strickland
  • 590
  • 4
  • 14
2
votes
2 answers

F# Array2D - Extract Diagonals

Let us say I have a matrix [[0; 0; 1; 0; 0; 0] [0; 1; 0; 0; 0; 0] [2; 0; 0; 0; 0; 0] [0; 1; 0; 0; 0; 0] [0; 0; 1; 0; 0; 0] [0; 0; 0; 1; 0; 0]] I want to extract the diagonals as a 1d array meaning [|2;1;1|] and [|2;1;1;1|] For rows and…
Nulle
  • 1,301
  • 13
  • 28
2
votes
1 answer

How to iterate a 2d array diagonally from top left to bottom right

I am trying to iterate a square 2d array for all diagonals from top left to bottom right. I have code to iterate from bottom left to top right but I need to adapt it to also iterate the other way. public static void main(String[] args) { …
Rpp
  • 103
  • 1
  • 12
2
votes
2 answers

Create a new large matrix by stacking in its diagonal K matrices

l have K (let K here be 7) distincts matrices of dimension (50,50). I would like to create a new matrix L by filling it in diagonal with the K matrices. Hence L is of dimension (50*K,50*K). What l have tried ? K1=np.random.random((50,50))…
Taylor
  • 127
  • 1
  • 10
2
votes
7 answers

How to get diagonal values from specific point?

Suppose I have 10x10 matrix with the following data: 1 2 3 4 5 6 7 8 9 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 …
Jamy
  • 115
  • 1
  • 9
2
votes
1 answer

Calculate the diagonal of a big.matrix in R

I am working with several big squared matrices of 1.3e6 rows, and I want to the diagonal of all of them. I need an efficient way to do it, but I can not use diag() library(bigmemory) A=big.matrix(nrow=1.3e6,ncol=1.3e6,init=3) diag(A) Any…
LauC
  • 55
  • 5
2
votes
2 answers

Unity: Diagonal movement not corresponding to correct key inputs

I've been trying to find a solution for this issue for a while now with no luck. I want to be able to move in 8 directions but for some odd reason, my player only wants to move in 6 directions. When I press: W+D or W+A, it moves towards the top…
Redza R.
  • 21
  • 2
2
votes
1 answer

Is there a function to get the skew diagonal of a matrix in matlab?

A=[a_11, a_12; a_21, a_22] The skew diagonal is [a_12, a_21]. Right now, I flip the matrix around and use diag.
user564376
2
votes
1 answer

Diagonal sum with constraints in r

I want to extract cells with the two constraints. first, extract data[i,j+@] if sum(data[i,j+@])<5, else extract data[i+1,j]. second, I want to set the constraint value of each row is 5, I want to work on the next row if the sum up to the second…
eun lee
  • 145
  • 8
2
votes
1 answer

illegal syscall in c++ testing program (the sum of the diagonal matrix elements program)

I've just started to learn programming so I'm asking for your understanding ;) the checking program accepts only a few tests on the rest throws the error illegal syscall and I have no ideas how to "bite it". task: (ATTENTION, the program should be…
MencX
  • 23
  • 2