问题标签 [submatrix]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
matrix - 如何在犰狳中加入矩阵
我有几个进程,每个进程都计算自己的矩阵。最后,我希望他们将求解的矩阵发送到根进程,根进程将把它们合并成一个大矩阵,并以 ASCII 格式将其简单地输出到文本文件中。是否有可能以某种优雅的方式,或者我必须遍历每个矩阵并自己“加入”它?
例子:
ocaml - 编写一个 OCaml 程序,检查矩阵 A 是否包含在矩阵 B 中
尽管 Java 没有遇到任何重大问题,但关于 OCaml 编程语言,我不能这么说。我应该subMat
为两个矩阵创建一个函数,检查矩阵 A 是否是矩阵 B 的子矩阵,如果是 - 返回 true -val subMat: int list list -> int list list -> bool = <fun>
我会很感激任何帮助,因为我真的不知道如何解决这个问题。
matlab - 如何制作一个以n为参数的函数并在matlab中创建子矩阵
大家好,我遇到了一个问题。我将创建一个名为 quadrants 的函数,该函数将一个名为 n 的标量整数作为其输入参数。该函数返回 Q,一个 2n×2n 矩阵。Q 由四个 n×n 子矩阵组成。左上角子矩阵的元素都是1s,右上角子矩阵的元素是2s,左下角的元素是3s,右下角的元素是4s。
提前感谢您的帮助..
arrays - partition a matrix into matrix of blocks
I want to divide an image data into blocks, for example if I have X matrix of 4*4, I want the result to be a matrix M of 2*2*2*2 where M(1,1,:,:)=X(1:2,1:2) and M(1,2,:,:)=X(1:2,3:4) and etc.
I found a way to divide it into a cell array using mat2cell but cell arrays seem not very supported in matlab, I search and ask on SO just to do things that can be done easily with ordinary matrices(and I get answers suggesting not to use cell arrays at all).
I searched the net and SO thoroughly , there are many many results all of them either solve a particular problem(like finding a solution to an equation, which I don't want here) or end up at suggesting mat2cell.
The closest result I found though is using reshape, I tried reshape(X,[2 2 2 2])
and got C=2*2*2*2 matrix but C(1,1,:,:) seems to be the first row of X not the first block and I can't figure out what to do next.
Someone suggested permute(C,[1 2 3 4])
but I still don't get the result I want.
I'm still beginner to matlab so forgive me if my question is simple, also I don't want for-loops, I want vector code, so What to do next after reshape ?
Edit
I tried the answer of that duplicate question and still I don't get the result I want, I tried these:
T was 10*10*4*4, exactly the size I want(40*40 into a matrix of submatrices each of 4*4) but the values are wrong, T(1,1,:,:)~=A(1:4,1:4)
What Am I doing wrong here ?
r - 将子矩阵中的值分配给更大的矩阵
我有一堆小矩阵,它们基本上是更大矩阵的子集,但具有不同的值。我想从这些子矩阵中获取值并覆盖较大矩阵中的相应值。例如,假设这是我更大的矩阵:
一个较小的矩阵可能只是:
因此,例如,我想从较小矩阵 (2.5) 中 AB-2000 行和 AB-3500 列的交点中获取值,并将其设置为较大矩阵中的新值,并为子矩阵中的其他值,所以我们得到一个新的更大的矩阵,如下所示:
我有很多子矩阵,我用它们的值来覆盖较大矩阵中的值,所以想要一种有效地做到这一点的方法。有什么想法吗?
arrays - 在 Matlab 中为索引子矩阵的子矩阵赋值
我不确定我是否习惯于更正标题中的措辞来描述问题。请随意编辑它以反映下面的描述。
假设我有一个数独求解程序,假设输入矩阵如下,
我从 1 到 9 逐列索引 3x3 子矩阵。假设表示该索引的变量nSubMat可以采用 1 到 9 之间的任何值。
我按以下方式索引子矩阵,
现在,我想访问和修改 SubMat 的 (2x3) 位置中的值,而不必首先创建 SubMat(比如避免不必要的副本)。
详细地说,如果我有一个函数 submatrix() 可以实现上述内容,我的语句将如下所示,
甚至,
我知道 Matlab 解释器会自动优化 LHS=RHS 类型分配以提高速度,但上述矩阵运算很重要,原因(算法上)不仅仅是减少副本和加速代码,我不会在这里详述。我在一个名为 Armadillo 的 C++ 库中看到了所需的语法,但我不确定 MATLAB 是否也能做到这一点。
arrays - 在 MATLAB 的一个命令中选择子矩阵和向量化
假设我们有一个 ArrayA = ones(2, 2, 2)
和另一个 matrix P = rand(4)
。我想知道是否可以编写代码
放入一行代码以节省temp
. 我试着跑
但这不起作用。我也摸索了这个reshape
命令,但无法让它工作。
我无法使用网络或此论坛找到答案。有可能做我想要的吗?
感谢您的帮助,
阿德里安
matlab - matlab/numpy 子矩阵轮廓
我正在寻找一种方法来获取 matlab/numpy 子矩阵的轮廓。例如,如果我有:
有没有办法让 [1,2,3,4,6,10,9,8,7,5] 比切片每条边然后连接它们更快(即更具可读性)?
编辑:问题是用 numpy 切片很麻烦。例如,假设我有 i0,i1,j0,j1 来识别子矩阵:
我想做: np._r[A[i0,j0:j1+1],A[i0:i1+1,j1],A[i1,j1:j0-1:-1],A[i1:i0 -1:-1,j0]]
但是如果 j0==0,[j1:j0-1:-1] 不起作用,因为 [j1:-1:-1] 返回一个空切片...
编辑 2:以下切片似乎有效,我不确定它是否真的很好,但我还没有做得更好。
仍然感谢所有回答的人,如果您找到了更好的方法,请不要犹豫发布。
matlab - 如何在Matlab中找到矩阵中每X行的总和
我有一个 189 x 4914 矩阵,并试图找到每个 1x26 子矩阵中每一行的总和。我该怎么办?
非常感谢。
python-2.7 - 使用 Numpy 从矩阵中提取所有方形子矩阵
假设我有一个 NxN numpy 矩阵。我正在寻找从该矩阵中提取所有方形块(子矩阵)的最快方法。表示0 < C < N+1的原始矩阵的所有 CxC 部分。子矩阵应对应于原始矩阵的连续行/列索引。我想在尽可能短的时间内实现这一目标。