Skip to main content
edited title
Link
user64494
  • 29.1k
  • 4
  • 29
  • 56

using Using DeleteCases to delete vectors with particular index as 0

Tweeted twitter.com/StackMma/status/1083106254925512704
Source Link
cleanplay
  • 690
  • 3
  • 11

using DeleteCases to delete vectors with particular index as 0

Assume I have a set of vectors

  set = {{0,1,1,0,1}, {1,0,1,1,1}, {1,1,1,1,0},{1,0,0,1,0}}. 

I want to delete the vectors which have the last entry as 0. In the above example, it is the 3rd and 4th vectors.

Can I use DeleteCases in a better way than following?

 Do[If[set[[j]][[5]] == 0, set[[j]] = ConstantArray[0, Length[set[[1]]]]], 
 {j, 1, Length[set]}];

 set =  DeleteCases[set, ConstantArray[0, Length[set[[1]]]]];