块状提取物子矩阵 [英] Numpy extract submatrix
本文介绍了块状提取物子矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在numpy
中我是一个新手,我很难理解如何从np.array
中提取具有已定义的列和行的子矩阵:
I'm pretty new in numpy
and I am having a hard time understanding how to extract from a np.array
a sub matrix with defined columns and rows:
Y = np.arange(16).reshape(4,4)
如果要提取第0行和第3行/列,则应具有:
If I want to extract columns/rows 0 and 3, I should have:
[[0 3]
[12 15]]
我尝试了所有的重塑功能...但是无法弄清楚该怎么做.有什么想法吗?
I tried all the reshape functions...but cannot figure out how to do this. Any ideas?
推荐答案
This returns your desired result:
In [25]: Y = np.arange(16).reshape(4,4)
In [26]: Y[np.ix_([0,3],[0,3])]
Out[26]:
array([[ 0, 3],
[12, 15]])
这篇关于块状提取物子矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文