如何在朱莉娅的矩阵中删除列?

发布于 2025-02-13 04:44:22 字数 242 浏览 1 评论 0原文

如果我有一个矩阵m,以便m = [0 1 2; 3 4 5; 6 7 8],如何删除指定的列。例如,在删除第二列后,m将为[0 2; 3 5; 6 8]

numpy中,存在一个numpy.delete函数,可以执行我的要求(沿特定轴删除),但是我不确定朱莉娅等效的是什么。

If I had a matrix M such that M = [0 1 2; 3 4 5; 6 7 8], how could I delete a specified column. For example, after I deleted the second column M would be [0 2; 3 5; 6 8].

In numpy, there exists a numpy.delete function that does what I ask (deleting along a specific axis), but I am unsure as to what the Julia equivalent is.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

千年*琉璃梦 2025-02-20 04:44:22

您可以通过数组索引直接执行此操作,

julia> M = [0 1 2; 3 4 5; 6 7 8];

julia> M[:, 1:3 .≠ 2]
3×2 Matrix{Int64}:
 0  2
 3  5
 6  8

请注意,\ neq + TAB

或使用

julia> using InvertedIndices

julia> M[:, Not(2)]
3×2 Matrix{Int64}:
 0  2
 3  5
 6  8

You can do it directly with array indexing,

julia> M = [0 1 2; 3 4 5; 6 7 8];

julia> M[:, 1:3 .≠ 2]
3×2 Matrix{Int64}:
 0  2
 3  5
 6  8

note that is written as \neq + Tab from keyboard.

Or using packages like InvertedIndices.jl:

julia> using InvertedIndices

julia> M[:, Not(2)]
3×2 Matrix{Int64}:
 0  2
 3  5
 6  8
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文