2

I have three numpy arrays

x =np.array([1,2,3,4,2,1,2,3,3,3])
y =np.array([10,20,30,40,20,10,20,30,39,39])
z =np.array([100,200,300,400,200,100,200,300,300,300])

I want to check if x[i]==x[j] and y[i]==y[j] and z[i]!=z[j]. If this is true I want to remove z[j].

In pseudo code:

label: check
for i in range(0,np.size(x)):
  for j in range(0,np.size(x)):
    If x[i] == x[j] and y[i]==y[j] and z[i]!=z[j] and i<j:
      x = delete(x,j)
      y = delete(y,j)
      z = delete(z,j)
      print "start again from above"
      goto check

Since I use goto and I don't know any other way around this I want to ask if there is any quick and elegant way to do this (maybe based on numpy predefined functions)?

1 Answer 1

1

This should do it:

np.unique(np.array([x, y, z]), axis=1)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.