Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
只是一个简单的问题,如果我有一个有 n 行和 m 列的矩阵,我怎样才能切断矩阵的 4 个边并返回一个新矩阵?(新矩阵将有 n-2 行 m-2 列)。
提前致谢
a[1:-1, 1:-1]
一个更普遍的答案是:
a[[slice(1, -1) for _ in a.shape]]