Help: Remove one column of M*N array using index?

2,323 views
Skip to first unread message

Helen

unread,
Apr 5, 2014, 11:32:46 PM4/5/14
to juli...@googlegroups.com
Does someone know how to remove one column by using index? 
Just as the in Matlab, you can use A[:,1]=[] to remove the first column or use  x[,-1] in R.
I don't want to use the way like A[:,[2,4:end]] to remove the third column.

Appreciate for the help!

Tony Kelman

unread,
Apr 6, 2014, 4:31:07 AM4/6/14
to juli...@googlegroups.com
This kind of question usually should go do julia-users instead of julia-dev, but it's a good question regardless.


This is a bit more verbose than in Matlab (though the delete-and-copy behavior of Matlab is pretty slow), but appears to work:

A[:, 1:size(A,2) .!= 3]

-Tony

Milan Bouchet-Valat

unread,
Apr 6, 2014, 6:21:35 AM4/6/14
to juli...@googlegroups.com
For the sake of completeness, in the future you should be able to write something like
A[:, !3]

See https://github.com/JuliaLang/julia/issues/1032


Regards

Kevin Squire

unread,
Apr 6, 2014, 10:55:19 AM4/6/14
to juli...@googlegroups.com
Also for the sake of completeness: until you can write A[:, !3]A[:, 1:size(A,2) .!= 3] is going to make a copy of the array (which is what matlab does).  With large arrays, this is rather inefficient, which I think is one of the reasons it isn't easier in julia.

Cheers, Kevin
Reply all
Reply to author
Forward
0 new messages