0

I have a 1D Array. we call grid_pro_x. it Shows the Position of particles. it is from -100 to 100 micro meter. I have also another 1D Array, Px_pro which is the energy of particles. I want to extract Px_pro array for those particles which their position is beyond 10 micrometer. I did something like that

len= len(grid_pro_x)
print len  ,' Number of initial X point'
<<<<320000

grid = np.where(grid_pro_x<10.e-06,0.,grid_pro_x) 
grid = np.extract(grid !=0,grid)
print np.shape(grid),' Number of elements grid'

<<<24000

np.where(grid_pro_x<10.e-6,0.,Px_pro)
Px_pro_new = np.extract(Px_pro !=0,Px_pro)
print np.shape(Px_pro_new),' Number of elements Px_pro-new'
<<<<320000

as you can see in the final line instead of 24000 I have 320000. can anyone help me what I have to do??

Thanks

1
  • 1
    Your description is a bit hard to understand. Can you give two example arrays and the desired output? Commented Aug 3, 2017 at 12:26

1 Answer 1

1

No need to use np.where().

numpy.abs(grid_pro_x) > 10e-6

will give you a boolean array marking which elements fulfill the condition. This array you can then use to extract the values from pro_x:

pro_x[numpy.abs(grid_pro_x) > 10e-6]
Sign up to request clarification or add additional context in comments.

Comments

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.