1

How to search array at some selected values?. For this case I am searching the respective "direction" and "time" for the rain values at "5".

direction=['200','250','180','200','300','270','005','080']
time=['0000','0030','0100','0130','0200','0230','0300','0300']
rain=['15','20','100','5','23','12','5','30']

The expected arrays are like this:

new array=[['200','0130','5'],['005','0300','5']]

Anyone got any idea?. What shall I do after reshaping the data like this:

data3=np.zeros((len(direction1),3),dtype='object')
data3[:,0]=direction1
data3[:,1]=time1
data3[:,2]=rain

1 Answer 1

2

Simply with zip() function:

direction = ['200','250','180','200','300','270','005','080']
time = ['0000','0030','0100','0130','0200','0230','0300','0300']
rain = ['15','20','100','5','23','12','5','30']

result = [list(t) for t in zip(direction, time, rain) if t[-1] == '5']
print(result)

The output:

[['200', '0130', '5'], ['005', '0300', '5']]
Sign up to request clarification or add additional context in comments.

2 Comments

@RomanPerekhrest..awesomw...happy for that..million thanks. What is the meaning of t[-1] ???...
@Azam, welcome. [-1] points to the last item of the sequence.

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.