diagonal

Extended block diagonal matrix in Matlab

帅比萌擦擦* 提交于 2019-11-30 22:26:46
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 elsewhere: I guess this can be hardcoded with loops, but I would like to find a more elegant solution. Any ideas on how to implement such a thing? P.S. I diag command, that using diag(A,k) returns the k th diagonal. I need something for writing in the matrix, for k >0, and for block matrices, not only elements. There is a submission on the File

Create a UIView with only one diagonal side

六眼飞鱼酱① 提交于 2019-11-30 20:18:31
I need to create a UIView that has the left border inclined with 45 degrees I was wondering,is there a way to acheive this programmatically? Does CATransform3D help me in this case since it’s not really a “3D rotation”? Edit Here's an image explaining more my needed output Fogmeister If you just want the shape with no content then you can create a CAShapeLayer and add it to your view's layer. (In fact you can also put content in there using this method but you'll need to alter it a bit). CAShapeLayer *layer = [CAShapeLayer layer]; UIBezierPath *path = [UIBezierPath bezierPath]; [path

How to split diagonal matrix into equal number of items each along one of axis?

一笑奈何 提交于 2019-11-30 08:52:40
问题 I have a very large diagonal matrix that I need to split for parallel computation. Due to data locality issues it makes no sense to iterate through the matrix and split every n -th calculation between n threads. Currently, I am dividing k x k diagonal matrix in the following way but it yields unequal partitions in terms of the number of the calculations (smallest piece calculates a few times longer than the largest). def split_matrix(k, n): split_points = [round(i * k / n) for i in range(n +

Create a UIView with only one diagonal side

旧时模样 提交于 2019-11-30 04:22:33
问题 I need to create a UIView that has the left border inclined with 45 degrees I was wondering,is there a way to acheive this programmatically? Does CATransform3D help me in this case since it’s not really a “3D rotation”? Edit Here's an image explaining more my needed output 回答1: If you just want the shape with no content then you can create a CAShapeLayer and add it to your view's layer. (In fact you can also put content in there using this method but you'll need to alter it a bit).

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

别说谁变了你拦得住时间么 提交于 2019-11-30 04:12:21
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 = nc) microbenchmark( diag = diag(m), cond = m[row(m)==col(m)], vec = m[(1:nc-1L)*nc+1:nc], mat = m[cbind(1:nc,1:nc)], times=10) Comments : I tested these with identical . I took "cond" from one of the answers to this homework question . Results are similar with a matrix of integers, 1:26 instead of letters . Results : Unit: microseconds expr min lq mean median

Extract diagonals from a distance matrix in R

北城以北 提交于 2019-11-29 17:39:02
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 2.828427 3 5.385165 3.000000 4 8.062258 5.385165 2.828427 I want to get in a vector the values: 2.828427, 3.000000, 2.828427 Thanks! One work around is to convert the dist object to matrix and then extract elements where row index is one larger than the column index: mat = as.matrix(dist(mymatrix)) mat[row(mat) == col(mat) + 1] # [1] 2.828427 3.000000 2.828427 A seemingly complicated but extremely

NumPy k-th diagonal indices

╄→尐↘猪︶ㄣ 提交于 2019-11-29 11:36:16
问题 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 only returns the indices comprising the main diagonal, so at the moment I am doing: a += numpy.diag([5], -1) But that doesn't seem as nice or robust. :-) Is there a way in numpy to get indices for other than the main diagonal? 回答1: A bit late, but this

Extract sub- and superdiagonal of a matrix in R

邮差的信 提交于 2019-11-29 10:12:34
As the title implies, how does one extract the sub- and superdiagonal of a matrix? 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 You may need to reshape the results.... help(lower.tri) help(upper.tri) help(diag) upper.tri and lower.tri do not include the diagonals. 来源: https://stackoverflow.com/questions/9885067/extract-sub-and-superdiagonal-of-a

How to split diagonal matrix into equal number of items each along one of axis?

你离开我真会死。 提交于 2019-11-29 08:57:28
I have a very large diagonal matrix that I need to split for parallel computation. Due to data locality issues it makes no sense to iterate through the matrix and split every n -th calculation between n threads. Currently, I am dividing k x k diagonal matrix in the following way but it yields unequal partitions in terms of the number of the calculations (smallest piece calculates a few times longer than the largest). def split_matrix(k, n): split_points = [round(i * k / n) for i in range(n + 1)] split_ranges = [(split_points[i], split_points[i + 1],) for i in range(len(split_points) - 1)]

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

送分小仙女□ 提交于 2019-11-29 01:27:53
问题 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 = nc) microbenchmark( diag = diag(m), cond = m[row(m)==col(m)], vec = m[(1:nc-1L)*nc+1:nc], mat = m[cbind(1:nc,1:nc)], times=10) Comments : I tested these with identical . I took "cond" from one of the answers to this homework question. Results are similar with