matrix

Create binary matrix in Matlab reporting increasing number of ones

丶灬走出姿态 提交于 2020-08-08 06:55:50
问题 I would like your advise to write a Matlab code that creates a binary matrix A of size 31x5 such that the first row of A is [1 1 1 1 1] from the 2nd to the 6th of A we have 1 only once per row [1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1] from the 7th to the 16th row we have 1 twice per row [1 1 0 0 0 1 0 1 0 0 1 0 0 1 0 ...] from the 17th to the 26th row we have 1 three times per row from the 26th to the 31th row we have 1 four times per row I could that manually, but I would like to

Sliding window summation of a matrix

隐身守侯 提交于 2020-08-06 21:41:24
问题 I have a 50x50 matrix, and I'd like to sum up the values in every 10x10 (or another set size value - always square) overlapping grid i.e.: Overlapping windows are shown only in the diagonal for the sake of clarity. The first task I've tried to do is define the coordinates of each window: win=10; start = [1,10,1,10]; for y=1:(50-win) for g=1:(50-win) tmp = [start(g,1)+1,start(g,2)+1,start(end,3),start(end,4)]; start = [start;tmp]; end start(end+1,1:4) = [1,10,1+y,10+y]; end And then I'd loop

Sliding window summation of a matrix

时光怂恿深爱的人放手 提交于 2020-08-06 21:38:47
问题 I have a 50x50 matrix, and I'd like to sum up the values in every 10x10 (or another set size value - always square) overlapping grid i.e.: Overlapping windows are shown only in the diagonal for the sake of clarity. The first task I've tried to do is define the coordinates of each window: win=10; start = [1,10,1,10]; for y=1:(50-win) for g=1:(50-win) tmp = [start(g,1)+1,start(g,2)+1,start(end,3),start(end,4)]; start = [start;tmp]; end start(end+1,1:4) = [1,10,1+y,10+y]; end And then I'd loop

Sliding window summation of a matrix

元气小坏坏 提交于 2020-08-06 21:35:58
问题 I have a 50x50 matrix, and I'd like to sum up the values in every 10x10 (or another set size value - always square) overlapping grid i.e.: Overlapping windows are shown only in the diagonal for the sake of clarity. The first task I've tried to do is define the coordinates of each window: win=10; start = [1,10,1,10]; for y=1:(50-win) for g=1:(50-win) tmp = [start(g,1)+1,start(g,2)+1,start(end,3),start(end,4)]; start = [start;tmp]; end start(end+1,1:4) = [1,10,1+y,10+y]; end And then I'd loop

Use 2D matrix as indexes for a 3D matrix in numpy?

余生颓废 提交于 2020-08-06 12:48:29
问题 Say I have an array of shape 2x3x3, which is a 3D matrix. I also have a 2D matrix of shape 3x3 that I would like to use as indices for the 3D matrix along the first axis. Example is below. Example run: >>> np.random.randint(0,2,(3,3)) # index array([[0, 1, 0], [1, 0, 1], [1, 0, 0]]) >> np.random.randint(0,9,(2,3,3)) # 3D matrix array([[[4, 4, 5], [2, 6, 7], [2, 6, 2]], [[4, 0, 0], [2, 7, 4], [4, 4, 0]]]) >>> np.array([[4,0,5],[2,6,4],[4,6,2]]) # result array([[4, 0, 5], [2, 6, 4], [4, 6, 2]])

How to compute the power of a matrix in R [duplicate]

给你一囗甜甜゛ 提交于 2020-08-04 03:30:08
问题 This question already has answers here : A^k for matrix multiplication in R? (6 answers) Closed 7 years ago . I'm trying to compute the -0.5 power of the following matrix: S <- matrix(c(0.088150041, 0.001017491 , 0.001017491, 0.084634294),nrow=2) In Matlab, the result is ( S^(-0.5) ): S^(-0.5) ans = 3.3683 -0.0200 -0.0200 3.4376 回答1: > library(expm) > solve(sqrtm(S)) [,1] [,2] [1,] 3.36830328 -0.02004191 [2,] -0.02004191 3.43755429 回答2: After some time, the following solution came up: "%^%" <

list unique values for each column in a data frame

一笑奈何 提交于 2020-07-30 01:44:47
问题 Suppose you have a very large input file in "csv" format. And you want to know the different values that occur in each column. How would you do that? ex. column1 column2 column3 column4 ---------------------------------------- value11 value12 value13 value14 value21 value22 value23 value24 ... valueN1 valueN2 valueN3 valueN4 So I want my output to be something like: column1 has these values: value11, value21, ...valueN1 . but I don't need to see reoccurrences of the same value. I need this

list unique values for each column in a data frame

Deadly 提交于 2020-07-30 01:44:02
问题 Suppose you have a very large input file in "csv" format. And you want to know the different values that occur in each column. How would you do that? ex. column1 column2 column3 column4 ---------------------------------------- value11 value12 value13 value14 value21 value22 value23 value24 ... valueN1 valueN2 valueN3 valueN4 So I want my output to be something like: column1 has these values: value11, value21, ...valueN1 . but I don't need to see reoccurrences of the same value. I need this

How do I concatenate two one-dimensional arrays in NumPy?

爷,独闯天下 提交于 2020-07-22 21:34:03
问题 I have two arrays A = [a1, ..., an] and B = [b1, ..., bn] . I want to get new matrix C that is equal to [[a1, b1], [a2, b2], ... [an, bn]] How can I do it using numpy.concatenate ? 回答1: How about this very simple but fastest solution ? In [73]: a = np.array([0, 1, 2, 3, 4, 5]) In [74]: b = np.array([1, 2, 3, 4, 5, 6]) In [75]: ab = np.array([a, b]) In [76]: c = ab.T In [77]: c Out[77]: array([[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6]]) But, as Divakar pointed out, using np.column_stack

rotate matrix M*N anticlockwise

与世无争的帅哥 提交于 2020-07-22 08:35:51
问题 I am not able to rotate a M*N matrix in anticlockwise direction. My code is working properly for 3*3 matrix but when I try for any other case it is not working assume I am doing it for 4*4 matrix then only outer elements are rotating and inner 4 elements i.e. 6,7,10,11 are not rotating. My input is 1-16 numbers as 4*4 matrix { {1, 2, 3, 4}, {5, 6, 7, 8},{9, 10, 11, 12},{13, 14, 15, 16} } static void antirotatematrix(int m, int n, int mat[][]) { int row = 0, col = n-1; int prev, curr; while