Issue
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)
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?
Solution
Give np.ix_
a try:
Y[np.ix_([0,3],[0,3])]
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]])
Answered By - JoshAdel
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.