如何在Python中获得矩阵的子阵列
说我有以下数组j
:
[[1, 2, 3, 4, 5],
[7, 7, 7, 6, 4],
[1, 1, 2, 0, 0]]
如何获得2x2的子阵列,以便子阵列是:
[[1, 2],
[7, 7],]
直觉我假设j [0:2] [0:2]
>会做到这一点,但我得到了:
[[1, 2, 3, 4, 5], [7, 7, 7, 6, 4]]
say I have the following array j
:
[[1, 2, 3, 4, 5],
[7, 7, 7, 6, 4],
[1, 1, 2, 0, 0]]
how can I get the subarray of 2x2 so the subarray would be:
[[1, 2],
[7, 7],]
intuitively I assumed j[0:2][0:2]
would do the trick but I get:
[[1, 2, 3, 4, 5], [7, 7, 7, 6, 4]]
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要明确说出每行想要的内容:
You need to explicitly say what you want from each row:
在Numpy中,您可以做到这一点:
输出:
in numpy you can do this:
output:
您也可以做:
You could also do: