Message Boards Message Boards

0
|
4753 Views
|
3 Replies
|
5 Total Likes
View groups...
Share
Share this post:

[?] Delete a row in a matrix that contains 0s using DeteteCases?

I need a code that delete specific rows in a matrix (full line), but looking for specific values.

This case is OK, and the line {0,0} was deleted accordingly by the code "DeleteCases".

In[1]:=  data = {{1, 1}, {2, 2}, {3, 3}, {0, 0}, {4, 4}, {5, 5}, {6, 6}};

In[2]:= DeleteCases[data, {0, 0}]

Out[2]= {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {5, 5}, {6, 6}}

*MY QUESTION: However, I need delete all lines that contain specific values on both columns. Based on the folowing data, I need a code that find the zeros on all columns and, then, delete the rows {0,3} and {6,0}. Can I do it using "DeleteCases"?

data = {{1, 1}, {2, 2}, {0, 3}, {4, 4}, {5, 5}, {6, 0}};

The output should be the following matrix:

{{1, 1}, {2, 2}, {4, 4}, {5, 5}}

Thank you in advance. Gustavo

POSTED BY: Gustavo Dacanal
3 Replies

It works! Thank you!

POSTED BY: Gustavo Dacanal

Out the top of my head:

DeleteCases[data, {0, _}||{_,0}]
POSTED BY: Sander Huisman
Posted 5 years ago
In[2]:= Select[data, FreeQ[#, 0] &]
Out[2]= {{1, 1}, {2, 2}, {4, 4}, {5, 5}}
POSTED BY: Hans Milton
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract