matrix

rotate the outer ring of matrix in anticlockwise by k element and inner ring in clockwise by k element in java

£可爱£侵袭症+ 提交于 2020-08-26 07:27:43
问题 please help me to solve the below problem in java to rotate the outer ring of matrix in anticlockwise by k element and inner ring in clockwise by k element in java and the middle element remains constant. The sample input is m=5,n=6,k=1 where m is no of rows,n is no of column and k is the number of required shift and the input matrix is 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 and the expected output is 2 3 4 5 6 12 1 14 8 9 10 18 7 20 15 16 11 24 13 21

rotate the outer ring of matrix in anticlockwise by k element and inner ring in clockwise by k element in java

不羁岁月 提交于 2020-08-26 07:27:42
问题 please help me to solve the below problem in java to rotate the outer ring of matrix in anticlockwise by k element and inner ring in clockwise by k element in java and the middle element remains constant. The sample input is m=5,n=6,k=1 where m is no of rows,n is no of column and k is the number of required shift and the input matrix is 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 and the expected output is 2 3 4 5 6 12 1 14 8 9 10 18 7 20 15 16 11 24 13 21

Select an area on bitmap with 4 points using Matrix.setPolyToPoly

南笙酒味 提交于 2020-08-21 04:54:29
问题 I am playing with bitmap on Android and I am facing an issue when selecting an area on the bitmap using the 4 points. Not all the sets of 4 points work for me. In some cases, the result is just a blank bitmap instead of the cropped bitmap (like in the picture) and there is not any error in logcat(even memory error). Here is the basic code I used to do the transformation. import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics

creating n by n matrix with 1 in main diagonal and common value say 0.012 in the other cells using R software

北城余情 提交于 2020-08-10 18:50:23
问题 I want to create an n by n matrix that looks like this if n=4 and my alpha=0.01 then my matrix using R software I would appreciate if i can get something using this working to reproduce the matrix above n=5 i=0 alpha=0.01 R=matrix(nrow=n,ncol=n) while(i<n){ R[i+1,]=alpha i=i+1} R but with the above code, all my diagonals are 0.01. What am i doing wrong? 回答1: You can create a matrix of 0.01's and set the diagonal to 1: n <- 5 alpha <- 0.01 diagonal_val <- 1 m <- matrix(alpha, n, n) diag(m) <-

Fast transpose byte matrix [][]byte in Golang assembly

六眼飞鱼酱① 提交于 2020-08-10 13:08:58
问题 Matrix transpose in pure golang is slow, and using package gonum needs structure transformation which costs extra time. So a assembly version may be a better solution. Sizes of the matrix vary ( [][]byte ) or can be fixed ( [64][512]byte ), and the element type may be int32 or int64 for general scenarios. Below is a golang version: m := 64 n := 512 // orignial matrix M := make([][]byte, m) for i := 0; i < m; i++ { M[i] = make([]byte, n) } func transpose(M [][]byte) [][]byte { m := len(M) n :=

Sum of a list of matrices in R

守給你的承諾、 提交于 2020-08-10 05:27:42
问题 I am trying to put a list of matrices together in a list and then do summation inside of each list. Below are the simple example of the codes: Let's say if I have 4 matrices: x1 <- matrix(1:9, nrow = 3) x2 <- matrix(2:10, nrow = 3) x3 <- matrix(3:11, nrow = 3) x4 <- matrix(4:12, nrow = 3) And I want to put them into a list() in a way like this: [[1]] [[1]][[1]] [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 [[1]][[2]] [,1] [,2] [,3] [1,] 2 5 8 [2,] 3 6 9 [3,] 4 7 10 [[2]] [,1] [,2] [,3] [1,]

Matrix of all possible combinations of some indices in Matlab

做~自己de王妃 提交于 2020-08-08 06:56:10
问题 Consider a Matlab vector A of size 1xL , reporting some strictly positive integers. I want to construct a matrix T of size prod(A,2)xL reporting all the possible L -tuples from 1:1:A(1) , 1:1:A(2) , ..., 1:1:A(L) . For example, take L=3 and A=[2 3 1] . Then T can be constructed as [ca, cb, cc] = ndgrid(1:1:A(1), 1:1:A(2), 1:1:A(3)); T= [ca(:), cb(:), cc(:)]; How can I generalise the code above to a generic L ? 回答1: A minor modification of this answer works. The required changes are: Define