0

For example

From this array

[1,1,2,3,1,2,-1,2,-1]

I want to remove -1 then make [1,1,2,3,1,2,2]

I found function np.setdiff1d, but it sorts the final result automatically.

I want to remove only -1 and keep order of other item.

Is there any good idea?

whitebear
  • 8,922
  • 18
  • 81
  • 171

1 Answers1

1

x[x!=-1] would do the trick

x = np.array([1,1,2,3,1,2,-1,2,-1])

x = x[x!=-1]

print x
# [1 1 2 3 1 2 2]
Nidal Barada
  • 333
  • 2
  • 13