Tag: 矩阵

找出2d矩阵是否是另一个2d矩阵的子集

最近我参加了一个黑客马拉松,我开始了解一个试图在2d矩阵中找到网格forms的问题。一个模式可能是U,H和T,并将用3 * 3矩阵表示如果我想呈现H和U. +–+–+–+ +–+–+–+ |1 |0 |1 | |1 |0 |1 | +–+–+–+ +–+–+–+ |1 |1 |1 | –> H |1 |0 |1 | -> U +–+–+–+ +–+–+–+ |1 |0 |1 | |1 |1 |1 | +–+–+–+ +–+–+–+ 现在我需要将其搜索到10*10 matrix containing 0s and 1s最近也是唯一的解决方案我可以得到它的powershell算法O(n ^ 4)。在MATLAB和R等语言中有非常微妙的方法可以做到这一点但是不是在C,C ++中。 我尝试了很多在Google和SO上搜索这个解决方案。但我最接近的是这个SO POST ,它讨论了实现Rabin-Karp字符串搜索算法 。但是没有伪代码或任何post解释这个。可以任何人帮忙或者提供任何链接,pdf或一些逻辑来简化这个? 编辑 作为Eugene Sh。 […]

使用CSparse库在C中表示稀疏矩阵

我无法理解如何使用CSparese库轻松表示C中的稀疏矩阵。 这就是我想要的 | 6.0 0.0 2.0 | A = | 3.0 8.0 0.0 | | 6.0 0.0 1.0 | with | 40.0 | b = | 50.0 | | 30.0 | csparse的cs Struct就是这个 typedef struct cs_sparse /* matrix in compressed-column or triplet form */ { csi nzmax ; /* maximum number of entries */ csi […]

外部范围时未定义变量

编写一个程序,让用户抛出五个骰子并以“图形方式”显示结果屏幕。 该程序应该首先通过填充一个介于1之间的5个数字的数组来模拟五个掷骰子然后,函数应该通过在屏幕上显示字符和计算函数来“绘制”结果总和。 我得到第一个函数的错误消息,它说我没有定义矩阵,我在“if”中定义了。 #include int sumOfDie(int inputArray[], int arraySize); int drawDie(int inputArray[], int arraySize) { int i, row, column=0; for (i=0; i<arraySize; i++) //determine the graphic number from the random number { if (inputArray[i]==1) { char matrix [3][4] = {{" "},{" * "},{" "}}; } if (inputArray[i]==2) { char matrix [3][4] = {{"* "},{" "},{" […]

计算矩阵乘法时的分段错误(核心转储)错误

我试图在C中实现矩阵乘法。如果我使用矩阵大小超过3,我会得到分段错误错误。对于2×2矩阵,这个代码它完美地工作。 我试图找出原因。 这是我的代码。 请看看它,让我知道我在哪里做错了。 #include #include #include /* matrix data structure. rs = row start re = row end cs = column start ce = column end a = pointer to array of pointers */ typedef struct _matrix { int rs; int re; int cs; int ce; int **a ; }matrix; matrix random_matrix(int n) { […]

将两个矩阵乘以不同的维度

我正在编写一个乘法矩阵的应用程序。 这适用于nxn矩阵a和b的预期: for(k = 0; k < n; k++) { for(i = 0; i < n; i++) { tmp = a[i][k]; for(j = 0; j < n; j++) { c[i][j] = c[i][j] + tmp * b[k][j]; } } } 如果a是nxy且b是yxm(暗示c是nxm)。 如何修改上述循环才能工作? 谢谢

从C C ++中的文件中读取矩阵

只是想知道,对于存储在文件中的矩阵,它是什么,即文件中的每一行是矩阵的一行,其中元素由空格分隔,我如何预先确定矩阵的大小,然后创建一个相同大小的数组并在C和C ++中读入数组? 如果您有一些代码示例,那将不胜感激! 感谢致敬!

C编程; 生成具有随机数的二维矩阵,无需重复

我想通过在行和列中的元素中插入随机数而不重复来生成6×6矩阵。 到目前为止这是我的代码。 谢谢您的帮助! #include #include int main(void) { int array[6][6]; int rows, columns; int random; srand((unsigned)time(NULL)); for(rows=0;rows<6;rows++) { for(columns=0;columns<6;columns++) { random=rand()%36+1; array[rows][columns] = random; printf("%i",array[rows][columns]); } printf("\n"); } return 0; }

高效的访问矩arrays

高效的访问问题:我需要按列访问大型矩阵(超过2000×2000),我的算法需要1行传递和1列传递。 行传递对于内存效率(缓存未命中)是好的,但是如何减少列传递中的缓存未命中? 我需要效率。 我唯一拥有的是:声明n局部变量(基于内存获取大小), int a1, a2, a3, a4; for ( int j = 0 ; j < DIM_Y ; j+=4 ) for ( int i = 0 ; i < DIM_X ; i++ ) a1 = matrix[i][j]; … ; a4 = matrix[i][j+4]; // make the column processing on the 4 variables. 它是C或C ++,以及数组或int或char。 任何提议和评论都受到欢迎。 […]

Dijkstra在C中的邻接矩阵

我需要在C中使用Dijkstra算法的一些帮助。 我已经生成了我的邻接矩阵,看起来像: int mat[NB][NB] = {{0, 171, MAX, 132, […]}, {171, 0, 30, 39, […]}, , […]}; 我发现了这个实现: http : //www.answers.com/topic/dijkstra-s-algorithm-1但路径是一维数组,我的矩阵是一个二维数组。 有没有办法将一个变换到另一个? 或者也许有人有办法处理这种矩阵。 在此先感谢您的帮助

Pthreads矩阵乘法误差

我想在现有的串行矩阵乘法代码上使用pthreads。 我的目标是使用pthreads实现更好的执行时间,只是为了实现加速。 但那时我被困住了。 我的原始序列号,工作正常,我在大约15秒内完成1000×1000方阵乘法。 但是当我执行当前的pthreads程序时,我遇到了分段错误。 这是我的代码: #include #include #include #include int SIZE, NTHREADS; int **A, **B, **C; void init() { int i, j; A = (int**)malloc(SIZE * sizeof(int *)); for(i = 0; i < SIZE; i++) A[i] = malloc(SIZE * sizeof(int)); B = (int**)malloc(SIZE * sizeof(int *)); for(i = 0; i < SIZE; i++) B[i] […]