How to delete zeros from matrix?

How to delete zeros from matrix delete and delete! does not work?

2 Likes

Letā€™s say you have:

[1 0 1;
 0 1 1;
 0 0 1]

What do you want the result of ā€œdelete zerosā€ to be?

4 Likes

Just in case youā€™re talking about sparse matrices, then the functions youā€™re looking for are dropzeros() and dropzeros!().

2 Likes

in what packgate is because it doesn;t work?

ŠæŠ¾Š½, 28. Š¾Šŗт 2019. у 17:13 Jamie via JuliaLang julialang@discoursemail.com јŠµ Š½Š°ŠæŠøсŠ°Š¾/Š»Š°:

If dropzeros doesnā€™t work then it wonā€™t be applicable to your case ā€” it only applies to SparseArrays.

Probably what you want is something like filter(!iszero, A), which will return all nonzero elements as a vectorā€¦ but you could also reasonably want all rows without any nonzeros, or all rows that arenā€™t all nonzero, or ā€¦, or ā€¦

We need a bit more to go on :slight_smile:

2 Likes