matrix

MATLAB quick find of a vector in matrix

一个人想着一个人 提交于 2020-01-15 07:53:27
问题 I have a piece of code that works in the following way. There is a matrix of size n x 2 . Each element is an integer between 1 and some maximum, say m . I want to search for rows in this matrix, that is, given [v1, v2] , output the index of this. Right now, I am using: k = find(ismember(edges, [v1, v2], 'rows')); However, this is the bottleneck in my code because this is in linear time. I would like to implement some hashmap type structure for fast lookup. What would be an easy way to do this

Python: Is a multidimensional array (“matrix”) the same thing as lists within lists?

旧城冷巷雨未停 提交于 2020-01-15 07:44:41
问题 I'm trying to understand the differences between what people call matrices and what people call lists within lists. Are they the same in that, once created, you can do identical things to them (reference elements the same way within them, etc). Examples: Making lists within a list: ListsInLists = [[1,2],[3,4],[5,6]] Making a multidimensional array: np.random.rand(3,2) Stacking arrays to make a matrix: Array1 = [1,2,3,4] Array2 = [5,6,7,8] CompleteArray = vstack((Array1,Array2)) 回答1: A list of

顺时针打印矩阵

筅森魡賤 提交于 2020-01-15 07:32:29
顺时针打印矩阵 题目:输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下4 X 4矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1,2,3,4,8,12,16,15,14,13,9,5,6,7,11,10 思路1 :用4个变量控制打印的边界,顺时针打印即可 代码如下: import java . util . ArrayList ; public class Solution { public ArrayList < Integer > printMatrix ( int [ ] [ ] matrix ) { int row = matrix . length - 1 ; int col = matrix [ 0 ] . length - 1 ; int brow = 0 ; int bcol = 0 ; ArrayList < Integer > list = new ArrayList < > ( ) ; while ( brow <= row && bcol <= col ) { for ( int y = bcol ; y <= col ; y ++ ) { list . add ( matrix [ brow ] [ y ] ) ; } brow ++ ; for ( int x =

Combined Pearson/Spearman rank correlation matrix with significance stars in Stata

我只是一个虾纸丫 提交于 2020-01-15 07:11:34
问题 I want to calculate a correlation matrix, where the lower triangle consists of Pearson and the upper triangle consists of Spearman rank correlation coefficients. I am using corr and spearman , which works fine. But with corr I cannot get the significance (p-value or stars and so on). So I tried pwcorr, list which gives me the exact results but with significance. Using this "new combination" I cannot create the matrix as with corr . //Get Pearson Matrix corr var1 var2 var3 matrix R = r(C) /

Jenkins parameterized matrix job

纵饮孤独 提交于 2020-01-15 06:07:23
问题 I am in the process of setting up a Jenkins job to run a bunch of tests on some c++ code. The code is generated during one Jenkins job. There are a number of sub-projects, with their code in their own folders. My thought is to have a matrix job where each configuration runs the test on one folder of code files. There are two things that I am not sure the best way to do though... I would like to set up the matrix job to automatically pick up if more sub-folders are added. Something like

Convolution matrix for diagonal motion blur

試著忘記壹切 提交于 2020-01-15 05:34:18
问题 I know my question is not really a programming question but it came out of programming need. Does anyone happen to know the convolution matrix for diagonal motion blur. 3x3, 4x4 or 5x5 are all good. Thanks, 回答1: This is 5x5: 0.22222 0.27778 0.22222 0.05556 0.00000 0.27778 0.44444 0.44444 0.22222 0.05556 0.22222 0.44444 0.55556 0.44444 0.22222 0.05556 0.22222 0.44444 0.44444 0.27778 0.00000 0.05556 0.22222 0.27778 0.22222 I basically drew a diagonal line, and then blurred it a little. 来源:

Replace all rgb values above a threshold

瘦欲@ 提交于 2020-01-15 05:26:06
问题 I have a numpy 3 d array full of RGB values like for exemple shape = (height,width,3) matrix = np.array( [[[0,0.5,0.6],[0.9,1.2,0]]) I have to replace the RGB value if any of the values is above a threshold, for exemple threshold = 0.8, replacement = [2,2,2] then matrix = [[[0,0.5,0.6],[2,2,2]] How can I do this on a efficient mannner with numpy ? Currently I am using a double for loop and checking if any rgb value is above treshold, i replace it however this is quiet slow for n = 4000 array.

How to form a matrix from submatrices?

我是研究僧i 提交于 2020-01-15 03:43:07
问题 Let's say that I have these 4 submatrices: print(A[0]) print(A[1]) print(A[2]) print(A[3]) [[ 0. 1. 2.] [ 6. 7. 8.] [ 12. 13. 14.]] [[ 3. 4. 5.] [ 9. 10. 11.] [ 15. 16. 17.]] [[ 18. 19. 20.] [ 24. 25. 26.] [ 30. 31. 32.]] [[ 21. 22. 23.] [ 27. 28. 29.] [ 33. 34. 35.]] From this matrix: [[ 0 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 31 32 33 34 35]] How can I manage the submatrix to reproduce the original one? 回答1: With A as the input array

旋转矩阵

落花浮王杯 提交于 2020-01-14 17:34:38
class Solution: def rotate(self, matrix): """ :type matrix: List[List[int]] :rtype: void Do not return anything, modify matrix in-place instead. """ m = len(matrix) n = len(matrix[0]) for i in range(m): for j in range(i + 1): self.swap(matrix, i, j, j, i) for i in range(n // 2): for j in range(m): self.swap(matrix, j, i, j, n - 1 - i) def swap(self, matrix, i1, j1, i2, j2): matrix[i1][j1]= matrix[i2][j2] 来源: CSDN 作者: ailinyingai 链接: https://blog.csdn.net/ailinyingai/article/details/103975476

R, iterating over the row vectors of a matrix

我怕爱的太早我们不能终老 提交于 2020-01-14 14:59:31
问题 I have some vector vect and I want to iterate over the row vectors v of a matrix and calculate: cov(v, vect) . I tried: for(vect in mat2) #where mat2 is a 215 by 31 matrix However, each vector appeared to be a scalar with value 1. How do I iterate over the row vectors of a matrix? To make this even better, since I am interested in calculating the sum of cov(v, vect) where v is a row vector, how can I use the higher-order functions left-fold and right-fold 回答1: Are you looking for apply ?