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

Posted 3 months ago
417 Views
|
3 Replies
|
5 Total Likes
|
 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
3 Replies
Sort By:
Posted 3 months ago
 In[2]:= Select[data, FreeQ[#, 0] &] Out[2]= {{1, 1}, {2, 2}, {4, 4}, {5, 5}} 
 Out the top of my head: DeleteCases[data, {0, _}||{_,0}]