matrix

Passing a matrix in a function (C)

£可爱£侵袭症+ 提交于 2019-12-28 06:34:06
问题 I have an issue passing a matrix to a function in C. There is the function I want to create: void ins (int *matrix, int row, int column); but I noticed that in contrast to the vectors, matrix give me an error. How can I pass my matrix to a function so? EDIT --> there is the code: // Matrix #include <stdio.h> #define SIZE 100 void ins (int *matrix, int row, int column); void print (int *matrix, int row, int column); int main () { int mat[SIZE][SIZE]; int row, col; printf("Input rows: "); scanf

make efficient the copy of symmetric matrix in c#

拥有回忆 提交于 2019-12-28 06:25:09
问题 I want to store in an array a symmetric matrix for a matrix I was doing this double[,] mat = new double[size,size]; for (int i = 0; i < size; i++) { for (int j = 0; j <= i; j++) mat[i, j] = mat[j, i] = (n * other_matrix[i,j]); } If I want to store in an array double[] mat = new double[size*size]; instead of double[,] mat What would be the most efficient way? using mat[i*n+j] ? 回答1: Yes. Store the elements by row, where the i -th row and j -th column is stored in index k=i*NC+j with NC the

How do I calculate a word-word co-occurrence matrix with sklearn?

心不动则不痛 提交于 2019-12-28 05:29:06
问题 I am looking for a module in sklearn that lets you derive the word-word co-occurrence matrix. I can get the document-term matrix but not sure how to go about obtaining a word-word matrix of co-ocurrences. 回答1: Here is my example solution using CountVectorizer in scikit-learn. And referring to this post, you can simply use matrix multiplication to get word-word co-occurrence matrix. from sklearn.feature_extraction.text import CountVectorizer docs = ['this this this book', 'this cat good', 'cat

Finding connected components of adjacency matrix graph

耗尽温柔 提交于 2019-12-28 05:23:32
问题 I have a random graph represented by an adjacency matrix in Java, how can I find the connected components (sub-graphs) within this graph? I have found BFS and DFS but not sure they are suitable, nor could I work out how to implement them for an adjacency matrix. Any ideas? 回答1: You need to allocate marks - int array of length n, where n is the number of vertex in graph and fill it with zeros. Then: 1) For BFS do the following: Components = 0; Enumerate all vertices, if for vertex number i,

How do I convert a 2X2 matrix to 4X4 matrix in MATLAB?

时光毁灭记忆、已成空白 提交于 2019-12-28 04:26:06
问题 I need some help in converting a 2X2 matrix to a 4X4 matrix in the following manner: A = [2 6; 8 4] should become: B = [2 2 6 6; 2 2 6 6; 8 8 4 4; 8 8 4 4] How would I do this? 回答1: A = [2 6; 8 4]; % arbitrary 2x2 input matrix B = repmat(A,2,2); % replicates rows & columns but not in the way you want B = B([1 3 2 4], :); % swaps rows 2 and 3 B = B(:, [1 3 2 4]); % swaps columns 2 and 3, and you're done! 回答2: In newer versions of MATLAB (R2015a and later) the easiest way to do this is using

How to get all combinations from multiple arrays?

最后都变了- 提交于 2019-12-28 03:10:50
问题 Supposing I have these 3 arrays $array1 = array(1,2); $array2 = array(4,5); $array3 = array(7,8); I need this output 1 4 7 1 4 8 1 5 7 1 5 8 2 4 7 2 4 8 2 5 7 2 5 8 One of my problems is that my array myght vary from 3 to 15 different arrays and each myght be empty (I might add a 0 just not to be empty) or have many values. If I have an empty array I also need to count that as a valid column. These values will be used to fill up a database in a specific order. Is there any way I can do this?

Does Matlab eig always returns sorted values?

試著忘記壹切 提交于 2019-12-28 02:56:05
问题 I use a function at Matlab: [V,D] = eig(C); I see that V and D are always sorted ascending order. Does it always like that or should I sort them after I get V and D values? 回答1: V is NOT sorted in any order, except to correspond to the order of the associated eigenvalues. But perhaps you did not mean that. The eigenvalues TEND to be in descending order, but this is not assured at all. They tend to be in order because the largest tend to trickle out of the algorithm on top. Eig has no sort at

undefined reference to `std::ios_base::Init::Init()'

拥有回忆 提交于 2019-12-28 01:52:46
问题 I write this code to read 3 files, TM is the size of square matrix, LER the No. of rows of an array and from last value define a non-square matrix of (ler/2)*2 Then... the code read a file with some relations, all are numbers and are assign to C[ler]. Then ... C[ler] is assigned to B[ler/2][2]. Those coordinates, per row, in B[ler/2][2] are assign to a and b. a and b are the row and the column of the matrix A[tm][tm] where to add 1. My code crashes and I don't see what the error is. When I

undefined reference to `std::ios_base::Init::Init()'

二次信任 提交于 2019-12-28 01:52:06
问题 I write this code to read 3 files, TM is the size of square matrix, LER the No. of rows of an array and from last value define a non-square matrix of (ler/2)*2 Then... the code read a file with some relations, all are numbers and are assign to C[ler]. Then ... C[ler] is assigned to B[ler/2][2]. Those coordinates, per row, in B[ler/2][2] are assign to a and b. a and b are the row and the column of the matrix A[tm][tm] where to add 1. My code crashes and I don't see what the error is. When I

A proper way to create a matrix in c++

余生颓废 提交于 2019-12-27 23:41:27
问题 I want to create an adjacency matrix for a graph. Since I read it is not safe to use arrays of the form matrix[x][y] because they don't check for range, I decided to use the vector template class of the stl. All I need to store in the matrix are boolean values. So my question is, if using std::vector<std::vector<bool>* >* produces too much overhead or if there is a more simple way for a matrix and how I can properly initialize it. EDIT: Thanks a lot for the quick answers. I just realized,