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
  • 11,200
  • 24
  • 114
  • 237

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
  • 373
  • 2
  • 14