如何用矩阵的一些非连续行和列形成子矩阵 [英] How to form submatrices with some non-consecutive rows and columns of a matrix

查看:108
本文介绍了如何用矩阵的一些非连续行和列形成子矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个10 x 10的矩阵.我想使用第1列,第2列和第8列和行以外的所有行和列,从这个主矩阵形成一个子矩阵.
我知道可以使用Part来形成子矩阵,但是这些示例大多是关于仅使用连续的行和列来形成子矩阵的.

I have a 10 by 10 matrix. I want to form a sub-matrix from this main matrix, using all the rows and columns except the 1st, 2nd and 8th columns and rows.
I know Part can be used to form the sub-matrix, but the examples are mostly about forming the sub-matrix using consecutive rows and columns only.

推荐答案

如果这是您的矩阵:

tst = RandomInteger[10, {10, 10}];

这可以解决当前的问题:

This will do the trick for the case at hand:

tst[[{3, 4, 5, 6, 7, 9, 10}, {3, 4, 5, 6, 7, 9, 10}]]

您可以使用Complement[Range[10],{1,2,8}]代替显式列表.

Instead of explicit list, you could use Complement[Range[10],{1,2,8}].

这篇关于如何用矩阵的一些非连续行和列形成子矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆