0

Say I have two lists:

arrayA = np.array([3,4,1,2,5,6,8,6,3])
arrayB = np.array([4,2,5,6,1,3,6,5,3])

which basically represents a point in 2D.

I want to get a label list that looks like:

listLael = [type1,type2,type1,type2,...]

that have the same length as arrayA and arrayB and

type1 if arrayA value >= 5 and arrayB value >= 5
type2 if eith arrayA or arrayB value < 5

I know that I can go through both array and get it but is there are fast and convenient way of doing this with numpy array?

1 Answer 1

2

Use numpy.where:

>>> np.where((arrayA >= 5) & (arrayB >= 5), 'type1', 'type2')
array(['type2', 'type2', 'type2', 'type2', 'type2', 'type2', 'type1',
       'type1', 'type2'],
      dtype='|S5')
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Exactly what I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.