How to delete a row of matrix in julia

前端 未结 3 1862
抹茶落季
抹茶落季 2021-01-04 04:47

In matlab, deleting the 2nd row of matrix A is

A(2,:) = [];

How to delete a row of matrix in julia? I tried to use A(2,:

相关标签:
3条回答
  • 2021-01-04 05:26

    I don't know the first thing about Julia, but I think it uses square brackets ([]) for indexing, so you should try the following:

    A[2, :] = []
    

    I don't have a Julia interpreter at hand to test that, but if that also fails, surely the following should work:

    A = A[[1, 3:end], :]
    

    which simply uses the reverse strategy of selecting the rows that you want to keep.

    0 讨论(0)
  • 2021-01-04 05:36

    You can't delete a row from a matrix – the fact that Matlab has easy syntax for this is a bit of a trap because the actual way you have to delete a row is to create a copy without the row so we decided to make that explicit and thereby have more transparent performance characteristics. You can change the size of 1-dimensional arrays, e.g. doing push!(v,x) and pop!(v).

    0 讨论(0)
  • 2021-01-04 05:44

    I think this is the shortest answer A[1:size(A,1) .!= 2,: ]

    https://groups.google.com/forum/#!topic/julia-dev/goVB9Pp74H4

    0 讨论(0)
提交回复
热议问题