diagonal

R - transform upward diagonals to rows

你。 提交于 2019-12-24 05:03:01
问题 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 solutions are appreciated. As an example, suppose I am given the following data.table df1<-as.data.table(matrix(seq(1:100),nrow=20, byrow = TRUE)) > structure(df1) V1 V2 V3 V4 V5 1: 1 2 3 4 5 2: 6 7 8 9 10 3: 11 12 13 14 15 4: 16 17 18 19 20 5: 21 22 23

How to put a diagonal line over a textbox in CSS?

偶尔善良 提交于 2019-12-24 03:27:27
问题 Sorry about not having an example, but basically I want to give an effect of having a text box crossed out, like being cancelled, etc. Anyone got any ideas? 回答1: Here's another possible method, this one using the HTML5 canvas element to draw an 'x' over the textarea. http://jsfiddle.net/rmqJf/ Since I started working on it a bunch of other, answers popped up, some of them pretty similar. Lots of options to go with! I place the textarea directly on top of the canvas (of the same size), then

Build a block diagonal matrix from a known matrix

核能气质少年 提交于 2019-12-23 10:06:47
问题 I want to build a block diagonal matrix (A) from a known matrix (B) by putting B in diagonal positions of A. Let's say my B: > matrix(c(1,3,4,5),nrow=2) [,1] [,2] [1,] 1 4 [2,] 3 5 I am looking for a function like this: function(B,3) (3 is just a random number) which returns matrix A like this: [1,] 1 4 . . . . [2,] 3 5 . . . . [3,] . . 1 4 . . [4,] . . 3 5 . . [5,] . . . . 1 4 [6,] . . . . 3 5 Really appreciate any help 回答1: We can use bdiag library(Matrix) bdiag(replicate(3, B, simplify =

Outer function in R for upper triangular matrix

社会主义新天地 提交于 2019-12-22 10:58:32
问题 I have this code currently s1=seq(0,10,length.out=3) s2=seq(0,10,length.out=3) d=outer(s1,s2,`-`) I=outer(s1,s2,`==`) However I only want the upper triangular of d and I so I am currently doing d=d[upper.tri(d,diag=T)] I=I[upper.tri(I,diag=T)] Is there a way to make this code faster through incorporating the upper triangular matrix in the outer function? Note that this is a reproducible example, however my code is much bigger and I need to decrease the running time as much as possible. 回答1:

Lower triangular matrix in julia

佐手、 提交于 2019-12-22 08:49:58
问题 I have the number of columns equals the number of rows. And the the diagonal is is equal to zero. How can I build this matrix? #mat # [,1] [,2] [,3] [,4] #[1,] 0 NA NA NA #[2,] 1 0 NA NA #[3,] 2 4 0 NA #[4,] 3 5 6 0 I tried this x=rand(4,4) 4x4 Array{Float64,2}: 0.60064 0.917443 0.561744 0.135717 0.106728 0.72391 0.0894174 0.0656103 0.410262 0.953857 0.844697 0.0375045 0.476771 0.778106 0.469514 0.398846 c=LowerTriangular(x) 4x4 LowerTriangular{Float64,Array{Float64,2}}: 0.60064 0.0 0.0 0.0 0

matlab: filling matrix diagonalwise [duplicate]

夙愿已清 提交于 2019-12-20 06:21:14
问题 This question already has answers here : adding values to diagonals of matrix using element-wise addition in matlab (3 answers) Closed 4 years ago . I have an (2n-1)-by-1 vector with certain values and I want to obtain an n-n matrix with the diagonals filled using the same value. Eg. if I have a = [1; 2; 3; 4; 5]; I want to obtain A = [[3 4 5];[2 3 4];[1 2 3]] = 3 4 5 2 3 4 1 2 3 My matrix dimensions are a lot bigger so I'd want this as efficient as possible. I already found following

fill off diagonal of numpy array fails

最后都变了- 提交于 2019-12-20 02:31:11
问题 I'm trying to the fill the offset diagonals of a matrix: loss_matrix = np.zeros((125,125)) np.diagonal(loss_matrix, 3).fill(4) ValueError: assignment destination is read-only Two questions: 1) Without iterating over indexes, how can I set the offset diagonals of a numpy array? 2) Why is the result of np.diagonal read only? The documentation for numpy.diagonal reads: "In NumPy 1.10, it will return a read/write view and writing to the returned array will alter your original array." np.__version

How do you style triangular mask in CSS?

混江龙づ霸主 提交于 2019-12-13 16:25:12
问题 I have been looking at how to do this "inverse triangular" background using css. I am referring to the white diagonal parts on the bottom, on top of the background (fixed) image. The most I've gotten is to shapes, which aren't apparently a good solution having in mind that it is for a responsive design. I don't care if when the window is narrower there is just one diagonal, as long as there is no horizontal scroll. But shapes and its absolute width mess that up. I apologize if this is a silly

Diagonalize symbolic matrix

丶灬走出姿态 提交于 2019-12-13 13:25:45
问题 I need to diagonalize a symbolic matrix with python. In Mathematica it can be done easily, but when using the module numpy.linalg I get problems. For concreteness, consider the matrix [[2, x], [x, 3]] where x is a symbolic variable. I guess I get problems because the numpy package is provided for numerical computations, not symbolic, but I cannot find how to do it with sympy. 回答1: You can compute it from the eigenvalues, but there is actually a method that will do it for you, diagonalize In

Java 2D array diagonals for game

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 00:55:49
问题 To clarify I only wanted one or two for loops to help me on my way, preferably in the same style as I had used in the vertical :) I'm making a game using a 2D array, and I need a check that tests if at the current position (indicated by a green square) the character there is part of a diagonal sequence of "l" more of the character. 回答1: public static boolean diagonals(char[][] b, int row, int col, int l) { int counter = 1; // because we start from the current position char charAtPosition = b