diagonal

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

廉价感情. 提交于 2019-11-28 20:43:35
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 80k , so even if I didn't care about the speed/extra memory it simply wont fit in RAM. Strange, since Octave is a package for huge data sets and diagonals are very important, so it should be possible. The first element in the diagonal is the scalar product of the first row of A with the first column of B. The second element in the diagonal is the

Extracting off-diagonal slice of large matrix

风流意气都作罢 提交于 2019-11-28 07:37:06
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 slice" would return an nxn matrix of just those values. So for the matrix above and, say, 3, I'd get: 1 x x x x x 1 2 x x x x 1 2 3 x x x x 2 3 4 x x x x 3 4 5 x x x x 4 5 6 At the moment I'm using (forgive me) a for loop which is incredibly slow: getDiags<-function(ndiags, cormat){ resmat=matrix(ncol=ncol(cormat),nrow=nrow(cormat)) dimnames(resmat)

Extract sub- and superdiagonal of a matrix in R

a 夏天 提交于 2019-11-28 03:32:06
问题 As the title implies, how does one extract the sub- and superdiagonal of a matrix? 回答1: Using diag . For the superdiagonal, you just discard the last row and first column. For the subdiagonal, discard first row, last column: m <- matrix(1:9,nrow=3) > m [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 > diag(m) [1] 1 5 9 > diag(m[-nrow(m),-1]) [1] 4 8 > diag(m[-1,-ncol(m)]) [1] 2 6 回答2: You may need to reshape the results.... help(lower.tri) help(upper.tri) help(diag) upper.tri and lower.tri do

How to make a diagonal divider of zeros and ones using Matlab?

时间秒杀一切 提交于 2019-11-26 23:40:46
问题 This is the result that I want. The number of bits resolution are 256 x 256 . // assign default background to white. img = ones(256, 256); Example Result: 0 1 1 1 0 0 1 1 0 0 0 1 0 0 0 0 Is there a way that I can use the zeros() and ones() function in MATLAB to achieve this result? How should I do the looping? The result is something that eye() function can do, but it only do a diagonal lines. I want a diagonal lines that separate zeros and ones. 回答1: You are looking for the triu function img

Sum of antidiagonal of a matrix

我是研究僧i 提交于 2019-11-26 20:56:24
问题 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 5 7 I'm looking for the sum m[3, 1] + m[2, 2] + m[1, 3] , i.e. 1 + 2 + 1 I can't figure out how to set up an iteration. As far as I know there is no function for this (like diag() for the other diagonal). 回答1: Using m <- matrix(c(2, 3, 1, 4, 2, 5, 1, 3, 7), 3) 1) Reverse the

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

白昼怎懂夜的黑 提交于 2019-11-26 17:15:01
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, -4, 8]] Then the large diagonals are easy: l = len(matrix[0]) print [matrix[i][i] for i in range(l)] # [-2, -6, 7, 8] print [matrix[l-1-i][i] for i in range(l-1,-1,-1)] # [ 2, 5, 2, -1] But I have trouble coming up with a way to generate all the diagonals. The output I'm looking for is: [[-2], [9, 5], [3,-6, 3], [-1, 2, 5, 2], [8, 7, 1], [-4, 3], [8], [2], [3,1], [5, 5, 3], [-2, -6, 7,

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

こ雲淡風輕ζ 提交于 2019-11-26 06:05:56
问题 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, -4, 8]] Then the large diagonals are easy: l = len(matrix[0]) print [matrix[i][i] for i in range(l)] # [-2, -6, 7, 8] print [matrix[l-1-i][i] for i in range(l-1,-1,-1)] # [ 2, 5, 2, -1] But I have trouble coming up with a way to generate all the diagonals. The output I\'m looking for

draw diagonal lines in div background with CSS

落爺英雄遲暮 提交于 2019-11-26 05:28:20
问题 I have a div for a preview box: HTML: <div class=\"preview-content\">PREVIEW</div> CSS: .preview-content { background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAAECAYAAACp8Z5+AAAAGklEQVQIW2NkYGD4D8SMQAwGcAY2AbBKDBUAVuYCBQPd34sAAAAASUVORK5CYII=) repeat; width: 100%; min-height: 300px; max-height: 300px; line-height: 300px; text-align: center; vertical-align: middle; font-size: 2em; } Question: how to add diagonal lines to div background like in the picture? note: with CSS only if