删除行和列的dumpy数组,给定的信息删除在另一个向量数组中

发布于 2025-01-21 14:34:55 字数 564 浏览 2 评论 0原文

我有以下代码:

deleterowandcolumns = np.array([0,3])

original = np.array ([
                 [1, 2, 3, 4],
                 [5, 6, 7, 8],
                 [9, 10, 11, 12],
                 [13, 14, 15, 16]
])

要删除的行和列包含在deleterowandColumns array中。我手动删除了指定的行和列,例如:

deleted = np.delete(original,(0,3), axis=0)
deleted = np.delete(deleted,(0,3), axis=1)

获得以下所需的输出:

 [[ 6  7]
 [10 11]]

但是,此方法是非常手动的,并且根本不使用deleterowandcolumns randay。有没有有效的方法?

I have the following code:

deleterowandcolumns = np.array([0,3])

original = np.array ([
                 [1, 2, 3, 4],
                 [5, 6, 7, 8],
                 [9, 10, 11, 12],
                 [13, 14, 15, 16]
])

The rows and columns to delete is contained in the deleterowandcolumns array. Manually, I deleted the specified rows and columns like:

deleted = np.delete(original,(0,3), axis=0)
deleted = np.delete(deleted,(0,3), axis=1)

The following required output is obtained:

 [[ 6  7]
 [10 11]]

However this method is very manual and does not use the deleterowandcolumns array at all. Is there an efficient way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文