matlab,matrix,vectorization,diagonal

I am just assuming from your your final lines in the question that you have v and you are looking to get B without loops. For the same, I think this would work for you - %// Input v(:, :, 1)=[1 2 3]'; v(:, :, 2)=[1 2 4]'; [M,~,P] =...

If you want to do everything in one go, you could do this: 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] = j > i...

matlab,matrix,variable-assignment,diagonal

ix=bsxfun(@plus,[1:n],[n-1:-1:0]'); %generate indices A=a(ix); or A=hankel(a) %might be faster than toeplitz because half the matrix is zero A(n:-1:1,1:n) here is what hankel does internally (at least in ML R2013a), adapted to this problem: c=[1:n]; r=[n-1:-1:0]'; idx=c(ones(n,1),:)+r(:,ones(n,1)); A=a(ix); I guess the bsxfun solution and what thewaywewalk supposed is the fastest...

Some thoughts: You don't need a list of all the diagonals, what you need is the two diagonals for each queen in the board If you really, really want all the diagonals then it's better to change the data structure. Although I'm certain that this problem can be solved using...

np.diag returns a view to the original array. This means later changes to the original array are reflected in the view. (The upside, however, is that the operation is in much faster than creating a copy.) Note this is only the behavior in some versions of numpy. In others, a...

java,arrays,matrix,multidimensional-array,diagonal

Here you are : class Diag { public static void main(String[] args) throws java.lang.Exception { int[][] elements = new int[][] { { 1, 5, 9, 13 }, { 2, 6, 10, 14 }, { 3, 7, 11, 15 }, { 4, 8, 12, 16 } }; int R = elements.length;...

python,arrays,numpy,indexing,diagonal

You can use following method: get the mask array fill diagonal of the mask to True select elements where elements in mask is True Here is the code: m=np.array([[0,2,4],[4,0,0],[5,4,0]]) mask = m > 0 np.fill_diagonal(mask, True) m[mask] ...

actionscript-3,flash,angle,diagonal

There's a good example of this at:- http://rhuno.com/flashblog/2011/11/18/calculating-angles-and-moving-objects-accordingly/ You want to do something like var angle:int = 270; var rads:Number = angle*Math.PI/180; var speed:int = 2; function moveBullet(e:Event) { e.currentTarget.x += Math.cos(rads) * speed; e.currentTarget.y += Math.sin(rads) * speed; } You'll need to set angle accordingly depending on which way...

You need to set the anchor point from where to apply the rotation. Your transform is changing the position, because it by default pivots from the center, which in this case is not what you want. Use in your css: .upper-triangle { ... -webkit-transform-origin: 0% 0%; transform-origin: 0% 0%; ......

The trouble seems to be here: def diagonal # measure = Math.hypot(@length, @width) measure = (@length.to_f ** 2) + (@width.to_f ** 2) measure.hypot(@length, @width) end You seem to begin to try to calculate the length yourself using Pythagoras' method, but then attempt to call the hypot method on a float....

probably best to create a new csv from the old one. (untested) import csv newlines = [] with open('csvfilename.csv', 'rb') as csvfile: reader = csv.reader(csvfile) i=0 for row in reader: newlines.append(row[:i] + [1] + row[i+1:]) i+=1 with open('newcsvfilename.csv','wb') as csvfile: writer = csv.writer(csvfile) writer.writerows(newlines) ...

Try this: m <- matrix(NA, ncol = length(diag), nrow = length(diag)) m[lower.tri(m)] <- offdiag m[upper.tri(m)] <- t(m)[upper.tri(t(m))] diag(m) <- diag m # [,1] [,2] [,3] [,4] [,5] # [1,] 1 1 2 3 4 # [2,] 1 1 1 2 3 # [3,] 2 1 1 1 2 # [4,]...

linux,keyboard,character,diagonal,xmodmap

Perhaps not (see How to map a X11 KeySym to a Unicode character?, which lacks some detail: In your example, 0x8fc is a hexadecimal keysym value. The "normal" arrows are these: 0x08fb U2190 # leftarrow 0x08fc U2191 # uparrow 0x08fd U2192 # rightarrow 0x08fe U2193 # downarrow There are several...

Summary As of R version 3.2.1 (World-Famous Astronaut) diag() has received an update. The discussion moved to r-devel where it was noted that c() strips non-name attributes and may have been why it was placed there. While some people worried that removing c() would cause unknown issues on matrix-like objects,...

matlab,matrix,vectorization,diagonal

Discussion and code This could be one approach with bsxfun(@plus that facilitates in linear indexing as coded in a function format - function out = bsxfun_linidx(A,a) %// Get sizes [A_nrows,A_ncols] = size(A); N_a = numel(a); %// Linear indexing offsets between 2 columns in a block & between 2 blocks off1...

In order to extend a line you need to translate an endpoint along a vector. Here's the formula and an example in WPF: class Program { static void Main(string[] args) { Point3D p1 = new Point3D(1, 1, 0.0); Point3D p2 = new Point3D(3, 3, 0.0); Vector3D v = p2 -...

If A were not diagonalizable, the vectors in P would be linearly dependent. However, due to numerical errors they might be just very close to being linearly dependent. For instance, consider P = array([[1, 0],[1, 0.001]]) let Pm1 = inv(P) Then P * Pm1 - eye(2) would be far from...

Another idea could be: DF = data.frame(c1 = 1:3, c2 = 4:6, c3 = 7:9) DF # c1 c2 c3 #1 1 4 7 #2 2 5 8 #3 3 6 9 mat = matrix(0, nrow = prod(dim(DF)), ncol = ncol(DF)) mat[cbind(seq_len(prod(dim(DF))), rep(seq_along(DF), each = nrow(DF)))] = unlist(DF) mat #...

python,arrays,numpy,multidimensional-array,diagonal

One way to create such a generalized diagonal view is to use the as_strided function from the module numpy.lib.stride_tricks. The stride for the axis associated with the diagonal of the two axes is the sum of the strides of those axes. For example: In [196]: from numpy.lib.stride_tricks import as_strided Create...

You can use row() and col() to identify row/column relationships. m <- read.table(text=" 1 2 3 4 100 8 12 5 14 99 1 6 4 3 98 2 5 4 11 97 5 3 7 2") vals <- sapply(2:8, function(j) sum(m[row(m)+col(m)==j])) or (as suggested in comments by [email protected]) vals...

If you're open to a css solution you could do something like this: Demo here: http://jsfiddle.net/jme11/D9M2L/ CSS body { background-color: #000; margin: 0px; } p { color: white; } section { position: relative; background: blue; color: #fff; text-align: center; } section:before { position: absolute; content:''; } section.diagonal { background: blue;...