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