diagonal

Extracting off-diagonal slice of large matrix

妖精的绣舞 提交于 2020-01-19 07:37:05
问题 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:

Extracting off-diagonal slice of large matrix

南楼画角 提交于 2020-01-19 07:36:28
问题 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:

Max value per diagonal in 2d array

点点圈 提交于 2020-01-13 09:15:13
问题 I have array and need max of rolling difference with dynamic window. a = np.array([8, 18, 5,15,12]) print (a) [ 8 18 5 15 12] So first I create difference by itself: b = a - a[:, None] print (b) [[ 0 10 -3 7 4] [-10 0 -13 -3 -6] [ 3 13 0 10 7] [ -7 3 -10 0 -3] [ -4 6 -7 3 0]] Then replace upper triangle matrix to 0: c = np.tril(b) print (c) [[ 0 0 0 0 0] [-10 0 0 0 0] [ 3 13 0 0 0] [ -7 3 -10 0 0] [ -4 6 -7 3 0]] Last need max values per diagonal, so it means: max([0,0,0,0,0]) = 0 max([-10,13

Max value per diagonal in 2d array

血红的双手。 提交于 2020-01-13 09:15:11
问题 I have array and need max of rolling difference with dynamic window. a = np.array([8, 18, 5,15,12]) print (a) [ 8 18 5 15 12] So first I create difference by itself: b = a - a[:, None] print (b) [[ 0 10 -3 7 4] [-10 0 -13 -3 -6] [ 3 13 0 10 7] [ -7 3 -10 0 -3] [ -4 6 -7 3 0]] Then replace upper triangle matrix to 0: c = np.tril(b) print (c) [[ 0 0 0 0 0] [-10 0 0 0 0] [ 3 13 0 0 0] [ -7 3 -10 0 0] [ -4 6 -7 3 0]] Last need max values per diagonal, so it means: max([0,0,0,0,0]) = 0 max([-10,13

Create diagonal border of a cell

橙三吉。 提交于 2020-01-12 03:29:31
问题 I wonder if it is even possible creating a table with diagonal border line using css or jquery just like below: Any ideas will be appreciated. 回答1: Anything is possible if you fiddle around with it long enough, here's an example using some creative borders and a lot of CSS: .arrow_box:after, .arrow_box:before { top: 100%; border: solid transparent; content: " "; height: 0; width: 0; position: absolute; pointer-events: none; } FIDDLE And another one using CSS3 rotate: -webkit-transform: rotate

Creating diagonal matrix from array of matrices in MATLAB

做~自己de王妃 提交于 2020-01-05 07:20:11
问题 I am interested how to create a diagonal matrix from an array of matrices. I created an array of matrices in MATLAB: X<62x62x1000> it consists of 1000 matrices with dimensions 62x62 I want to create a matrix of dimensions 62000x62000 with 1000 sub matrices from array X along main diagonal. Do you have any clue how to do this, except M=blkdiag(X(:,:,1), X(:,:,2), X(:,:,3)...) because that would be to much writing. 回答1: A possible solution M = kron(speye(1000),ones(62)); M(logical(M)) = X(:);

Iterate over diagonal elements of a Matrix in MatLab

↘锁芯ラ 提交于 2020-01-05 04:25:13
问题 I need to get the indexes of all diagonals in a matrix. The matrix can be non square. The diag function gives the values, but I need the coords. So for instance with this: [1 2 3; 4 5 6; 7 8 9] , I want [1 1; 2 2; 3;3] PLUS [2 6] and 3 because they are the upper diagonals of the matrix, and same for below i.e. [4 8] and 7 . So the full list of indexes is: [1 1; 2 2; 3 3], [1 2; 2 3], [1 3], [2 1], [3 2], [3 1] . And I need this in the other diagonal direction too... And it needs to work for

matlab efficient way to extract diagonals of a 3D matrix [duplicate]

帅比萌擦擦* 提交于 2019-12-25 06:40:23
问题 This question already has answers here : Extract diagonal element from each frontal slice of tensor (3 answers) Closed 3 years ago . I want to extract diagonals of a 3D matrix (Sigma below) into another 3D matrix (Sigma2 below). Sigma = repmat(magic(4),1,1,3); Sigma2 = nan(1,4,3); for i=1:3 Sigma2(1,:,i) = diag(Sigma(:,:,i)); end Is there a more efficient way for doing this? 回答1: You can. If you reshape Sigma to a matrix, selecting the diagonal of the 3D matrix is now selecting rows from a

Using strfind in Matlab for different diagonal directions in a Matrix

烂漫一生 提交于 2019-12-25 02:24:38
问题 Before anyone asks, this is a repost of an earlier question, but I cannot delete it because it has answers, so I am modifying it so that hopefully Daniel R will answer it! I have a grid of numbers and I want to read a string of numbers with strfind in any of the 8 directions. The non-diagonal ones I have managed to get to work fine, it is the diagonal ones that I have been struggling with (except for downRight which Daniel R helped me with earlier which I am very thankful for)! Here is the

Finding diagonal in 2D array and replacing with 0 above it

瘦欲@ 提交于 2019-12-24 15:19:00
问题 So the start is: Random r = new Random(); int[,] mas = new int[4, 5]; for (int i = 0; i < mas.GetLength(0); i++) { for (int j = 0; j < mas.GetLength(1); j++) { mas[i, j] = r.Next(1, 10); Console.Write("{0}\t", mas[i, j]); } Console.WriteLine(); } Console.WriteLine(); Looks something like 4 3 5 6 2 3 5 6 7 4 2 3 4 5 5 2 3 4 5 6 What i i need is to get 0 above the diagonal. 4 0 0 0 0 3 5 0 0 0 2 3 4 0 0 2 3 4 5 0 This is what i've got so far, no what i need , but atleast got some diagonal and