问题描述
我正在尝试删除mathematica中的两个矩阵.做到这一点的一种优雅方法如下所示,即在新矩阵中将其指定为
I am trying to delete both a matrix in mathematica. An inelegant way of doing it is as I do below, i.e specifying it in a new matrix as
S = Table[
Ss[[If[i < t, i, i + 1]]][[If[j < t, j, j + 1]]], {i, q}, {j, q}];
目标是消除行和列t.
where the goal is to eliminate row and column t.
确实要删除一行很容易Delete [Ss,t].对于专栏,我想我可以做
Indeed delete a line is easy Delete[Ss,t]. For the column column I suppose I could do
Transpose[Delete[Transpose[Ss,t]]]
我主要关心的是以尽可能最快的方式执行此操作.
My primary concern is to do it in a way that executes the fastest way possible.
更一般地说,是否有Mathematica运算符可以像不进行转置那样对行进行分割和切分一样容易?
More generally, is there a Mathematica operator that makes it as easy to slice and dice matrix columns as it is to do for rows without resorting to transpose?
推荐答案
我认为您正在寻找:
Drop[Ss,{t},{t}]
时间:
ClearAll["Global`*"];
First@Timing[a = RandomInteger[1000, {5000, 5000}];]
0.34
First@Timing[Drop[a, {2}, {2}]]
0.11
而
First@Timing[Transpose@Delete[Transpose@Delete[a, 2], 2]]
0.5
这篇关于在Mathematica中删除矩阵列的简单方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!