开发者

Selecting specific array positions in Python

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 wi开发者_开发技巧th 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?


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]])


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

docs

numarray is deprecated in favour of numpy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜