diagonal

fill off diagonal of numpy array fails

亡梦爱人 提交于 2019-12-01 22:41:27
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__ '1.10.1' Judging by the discussion on the NumPy issue tracker, it looks like the feature is stuck in

How can I assign a value to the diagonals of a 4-D matrix using linear indexing in MATLAB?

纵然是瞬间 提交于 2019-12-01 22:02:59
问题 I have a 4-D matrix A of size NxNxPxQ . How can I easily change the diagonal values to 1 for each NxN 2-D submatrix in a vectorized way? 回答1: Incorporating gnovice's suggestion, an easy way to index the elements is: [N,~,P,Q]=size(A);%# get dimensions of your matrix diagIndex=repmat(logical(eye(N)),[1 1 P Q]);%# get logical indices of the diagonals A(diagIndex)=1;%# now index your matrix and set the diagonals to 1. 回答2: You can actually do this very simply by directly computing the linear

How can I assign a value to the diagonals of a 4-D matrix using linear indexing in MATLAB?

前提是你 提交于 2019-12-01 19:27:46
I have a 4-D matrix A of size NxNxPxQ . How can I easily change the diagonal values to 1 for each NxN 2-D submatrix in a vectorized way? Incorporating gnovice's suggestion, an easy way to index the elements is: [N,~,P,Q]=size(A);%# get dimensions of your matrix diagIndex=repmat(logical(eye(N)),[1 1 P Q]);%# get logical indices of the diagonals A(diagIndex)=1;%# now index your matrix and set the diagonals to 1. You can actually do this very simply by directly computing the linear indices for every diagonal element, then setting them to 1: [N,N,P,Q] = size(A); diagIndex = cumsum([1:(N+1):N^2; N

Create slope full width css3

久未见 提交于 2019-12-01 09:58:44
问题 I'm trying to create a slope/diagonal with SVG (first time, other alternatives accepted) and im having a lot of issues with it. My goal is: Create a full width slope (ready for responsive) I want to have the slope on top of a div section and other on bottom if there is an alternative, to .svg, i would be glad to hear it This is how the slopes, should look like: initial webdesign design mockup how the slope has to be I don't want to use an .png , then it will blur and I want as perfect as

Create slope full width css3

被刻印的时光 ゝ 提交于 2019-12-01 09:30:48
I'm trying to create a slope/diagonal with SVG (first time, other alternatives accepted) and im having a lot of issues with it. My goal is: Create a full width slope (ready for responsive) I want to have the slope on top of a div section and other on bottom if there is an alternative, to .svg, i would be glad to hear it This is how the slopes, should look like: initial webdesign design mockup how the slope has to be I don't want to use an .png , then it will blur and I want as perfect as possible. Here's my test fiddle. The yellow part, should be the one with slope, on bottom or top of the div

Replace diagonals of a 2D array with python [duplicate]

笑着哭i 提交于 2019-12-01 06:33:51
This question already has an answer here: changing the values of the diagonal of a matrix in numpy 7 answers I have the following 2D array A=([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]) And I want to replace the main diagonal by the array a = ([0,2,15,20]) Therefore, the results must be A=([[0, 2, 3, 4], [5, 2, 7, 8], [9, 10, 15, 12], [13, 14, 15, 20]) I tried with np.diag(a, k=0) but it doesn't work because np.diag() creates a diagonal 2D array with the array "a". Is there a way to do that with numpy? The above example is the simplest one. I would like to be able to change

How to create a div with a diagonal (or angled) top line

∥☆過路亽.° 提交于 2019-12-01 04:13:34
I'm a newbie on CSS3 and all I know is self-learned, reading you guys or any other tutorials so after hours of researching and trial-error, I could really use your help :(. I'm trying to rotate JUST the top line of a div. This is what I did so far: http://blanc-design.com/sigma2/ On the footer, I have rotate two divs to create that effect. But what I want to do is to have a straight bottom line on the green div. This is an example of how I would like it to be: http://blanc-design.com/sigma2/ex.jpg I don't know if I'm explaining myself right. This is the CSS code I've used to rotate the divs:

Replace diagonals of a 2D array with python [duplicate]

 ̄綄美尐妖づ 提交于 2019-12-01 03:42:06
问题 This question already has answers here : changing the values of the diagonal of a matrix in numpy (7 answers) Closed last year . I have the following 2D array A=([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]) And I want to replace the main diagonal by the array a = ([0,2,15,20]) Therefore, the results must be A=([[0, 2, 3, 4], [5, 2, 7, 8], [9, 10, 15, 12], [13, 14, 15, 20]) I tried with np.diag(a, k=0) but it doesn't work because np.diag() creates a diagonal 2D array with

How to create a div with a diagonal (or angled) top line

十年热恋 提交于 2019-12-01 01:29:45
问题 I'm a newbie on CSS3 and all I know is self-learned, reading you guys or any other tutorials so after hours of researching and trial-error, I could really use your help :(. I'm trying to rotate JUST the top line of a div. This is what I did so far: http://blanc-design.com/sigma2/ On the footer, I have rotate two divs to create that effect. But what I want to do is to have a straight bottom line on the green div. This is an example of how I would like it to be: http://blanc-design.com/sigma2

Check if column or diagonal in matrix = x (Without Numpy)

依然范特西╮ 提交于 2019-12-01 01:25:12
I can use this code to check if a row in a matrix = x: q = [[1,2,1],[1,2,1],[2,1,2]] answer = [sum(row) for row in q] for i in range(0, len(q)): if answer[i] == 6: print "Player 2 won!" if answer[i] == 3: print "Player 1 won!" if answer[i] != 6 and 3: print "It's a tie!" How can I check if my matrix has a diagonal or column that = x, without using Numpy (Is there a mathematical way to do it as shown above?) Example: (X = something that doesn't matter) q = [[1,X,X],[1,X,X],[1,X,X]] Should print True q = [[1,X,X],[X,1,X],[X,X,1]] Should print True (Diagonal) q = [[X,X,1],[X,1,X],[1,X,X]] Should