diagonal

Diagonalize 2d matrix along one axis in numpy

ぐ巨炮叔叔 提交于 2019-12-10 18:33:39
问题 Given the matrix X in dimension of MxN. I want to create a diagonal matrix for every row of X. The result should be in MxNxN. How to do it efficiently? Thank you! 回答1: out = np.zeros((m, n, n)) out[:, np.arange(n), np.arange(n)] = X 来源: https://stackoverflow.com/questions/41915720/diagonalize-2d-matrix-along-one-axis-in-numpy

How to replace the the diagonal elements of a matrix by a vector in SymPy?

大城市里の小女人 提交于 2019-12-10 10:14:54
问题 I have a vector X which I created like this: from sympy import * x1 = Symbol('x1') x2 = Symbol('x2') x3 = Symbol('x3') X = Matrix([x1, x2, x3]) Then I also have a matrix myMat which just contains ones: myMat = ones(3, 3) Matrix([ [1, 1, 1], [1, 1, 1], [1, 1, 1]]) Now I would like to replace the diagonal of the matrix by my vector X ; my desired outcome looks like this: Matrix([ [x1, 1, 1], [1, x2, 1], [1, 1, x3]]) I can of course do it in a for-loop like this: for ind, el in enumerate(X):

How to create a diagonal sparse matrix in SciPy

不打扰是莪最后的温柔 提交于 2019-12-10 10:14:47
问题 I am trying to create a sparse matrix which has a 2D pattern run down the diagonal. This is probably easiest to explain with a quick example. Say my pattern is: [1,0,2,0,1]... I want to create a sparse matrix: [[2,0,1,0,0,0,0...0], [0,2,0,1,0,0,0...0], [1,0,2,0,1,0,0...0], [0,1,0,2,0,1,0...0], [0,0,1,0,2,0,1...0], [...]] The scipy.sparse.dia_matrix seems like a good candidate, however, I simply cannot figure out how to accomplish what I want from the documentation available. Thank you in

How can I get the real size of the (lcd) display diagonal, i.e. if a it is a 17 inch or 19 inch or other?

拥有回忆 提交于 2019-12-10 08:01:07
问题 This is useful for me because I have to map objects with a correct dimension on screen; if I'm using a 19" lcd with 1280x1024 resolution and a normal 96dpi setting then in order to map a correct 1-inch square I have to write a xaml like this <Rectangle Name="one_inch_side_on_19_inch_diag_display" Height="86" Width="86" Fill="Blue"/> where Width and Height are put to 86 because 86 ~= 96 (dots-per-inch) * 17 (inches) / 19 (inches) as windows assumes 96dpi on a 17" monitor as the base to

Diagonal line across view

余生颓废 提交于 2019-12-07 16:31:22
问题 Based on some condition, I have to diagonally cut the list cell. For this I have made diagonal drawable image using this code: diagonal_line.xml <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > <item android:top="0dp" android:bottom="0dp" > <rotate android:fromDegrees="315" android:toDegrees="315" android:pivotX="0%" android:pivotY="0%" > <shape android:shape="line" > <stroke android:width="10dp" android:color="@color/grey" /> <

Multiple constant to a matrix and convert them into block diagonal matrix in matlab

喜你入骨 提交于 2019-12-07 11:07:12
问题 I have a1 a2 a3. They are constants. I have a matrix A. What I want to do is to get a1*A, a2*A, a3*A three matrices. Then I want transfer them into a diagonal block matrix. For three constants case, this is easy. I can let b1 = a1*A, b2=a2*A, b3=a3*A, then use blkdiag(b1, b2, b3) in matlab. What if I have n constants, a1 ... an. How could I do this without any looping?I know this can be done by kronecker product but this is very time-consuming and you need do a lot of unnecessary 0 * constant

Why does it print twice the “big” diagonal (matrix)

爷,独闯天下 提交于 2019-12-06 21:40:33
I have a matrix like the following: ` matrix = [ ['P', 'o', 'P', 'o', 'P'], ['m', 'i', 'c', 's', 'r'], ['g', 'a', 'T', 'A', 'C'], ['n', 'n', 'e', 'r', 't'], ['a', 'g', 'o', 'd', 'o'], ['a', 'p', 'p', 'l', 'e'] ]` and this code which prints every letter in a 'diagonal rising to the right' way with repetitions: `test_word = '' for upper in range(len(matrix)): for rep1 in range(min(upper + 1, len(matrix[0]))): for rep2 in range(rep1, min(upper + 1, len(matrix[0]))): for j in range(rep1, rep2 + 1): test_word += (matrix[upper - j][j]) print(test_word) test_word = ''` output: ` P,m,m,mo,o,g,g,gi ...

rowsum for matrix over specified number of columns in R

删除回忆录丶 提交于 2019-12-06 05:39:44
问题 I'm trying to get the sum of columns in a matrix in R for a certain row. However, I don't want the whole row to be summed but only a specified number of columns i.e. in this case all column above the diagonal. I have tried sum and rowSums function but they are either giving me strange results or an error message. To illustrate, please see example code for an 8x8 matrix below. For the first row I need the sum of the row except item [1,1], for second row the sum except items [2,1] and [2,2] etc

How to create a diagonal sparse matrix in SciPy

时间秒杀一切 提交于 2019-12-06 00:43:33
I am trying to create a sparse matrix which has a 2D pattern run down the diagonal. This is probably easiest to explain with a quick example. Say my pattern is: [1,0,2,0,1]... I want to create a sparse matrix: [[2,0,1,0,0,0,0...0], [0,2,0,1,0,0,0...0], [1,0,2,0,1,0,0...0], [0,1,0,2,0,1,0...0], [0,0,1,0,2,0,1...0], [...]] The scipy.sparse.dia_matrix seems like a good candidate, however, I simply cannot figure out how to accomplish what I want from the documentation available. Thank you in advance N = 10 diag = np.zeros(N) + 2 udiag = np.zeros(N) + 1 ldiag = np.zeros(N) + 1 mat = scipy.sparse

CSS diagonal lines - how to fit into its parent element?

。_饼干妹妹 提交于 2019-12-05 22:35:33
How can I make a diagonal line fill in and fit into a box (just pure css - without any use of background image)? div.diagonal-container { border: 1px solid #000; width:400px; height:400px; margin: 0 auto; } .to-right, .to-left { border-top:1px solid #ff00ff; width:100%; -moz-transform: rotate(45deg); -o-transform: rotate(45deg); -webkit-transform: rotate(45deg); -ms-transform: rotate(45deg); transform: rotate(45deg); } .to-right { -moz-transform: rotate(-45deg); -o-transform: rotate(-45deg); -webkit-transform: rotate(-45deg); -ms-transform: rotate(-45deg); transform: rotate(-45deg); } <div