0

sorry for the easy question but I'm new to Python. I have a set of points with these coordinates:

x=part.points[:,0]
y=part.points[:,1]
z=part.points[:,2]

And I'd like to select only the points with z>0.5 and z<0.6. I guess I have to use a where operator but it doesn't work. I mean when I type

import numarray

I get that this module is not defined. Are there other solution to do what I need?

2
  • 1
    What kind of points are you talking about? What is part? What libraries are you using? What do you mean by "select"? x, y and z are variables that seem to hold some subsets of your points; what does that have to do with coordinates? Commented Jul 27, 2011 at 9:45
  • please clarify what kind of data structures you use. Commented Jul 27, 2011 at 9:45

2 Answers 2

1

Here is how it can be done with numpy:

In [34]: import numpy as np

In [35]: points = np.random.rand(100, 3)

In [36]: points[(0.5 < points[:,2]) & (points[:,2] < 0.6)]
Out[36]: 
array([[ 0.71524853,  0.09490989,  0.5053525 ],
       [ 0.71668105,  0.88735685,  0.52713089],
       [ 0.17376858,  0.28024362,  0.56543163],
       [ 0.97134163,  0.95498013,  0.57372901],
       [ 0.35755719,  0.70042594,  0.56379507],
       [ 0.31666818,  0.22316937,  0.50953021],
       [ 0.87787189,  0.35648375,  0.52159669],
       [ 0.77436531,  0.84893017,  0.51721675],
       [ 0.88997082,  0.14993883,  0.57662781],
       [ 0.40895133,  0.95472591,  0.58294156],
       [ 0.71299491,  0.09611201,  0.56360363],
       [ 0.68517509,  0.46743956,  0.54170775],
       [ 0.04632064,  0.56637214,  0.5319611 ],
       [ 0.7708119 ,  0.84934734,  0.58631465],
       [ 0.73931364,  0.34690535,  0.55264761]])
Sign up to request clarification or add additional context in comments.

Comments

0
import numpy as np
np.where(...)

docs

numarray is deprecated in favour of numpy

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.