Improving style (and speed)?
ingo
ingoogni at home.nl
Thu Aug 3 15:23:43 EDT 2000
Dear all,
A week or two ago I started learning programming and Python. Did a few small
things so far and they work :) Trying something bigger now; manipulating a
3D-dataset. There's one part in it, although it works, I don't like the way
I did it. But I can't find a better, more elegant, way to do it. Lack of
experience. So I'm looking for some guidance.
What I'm doing is select a small (3x3) region in the dataset. Within this
selection find the minimum value and its indices in the 3d-dataset . If
there are more minima select one randomly. I'm not yet taking into account
that the selection also can be 2x2, 2x3 or 3x2 when it's on one of te edges
of the dataset.
Coming from "Array3d[Posx, Posy, Posz]"
Miny=Posy-1
if Miny<0:
Miny=0
Maxy=Posy+2
Minz=Posz-1
if Minz<0:
Minz=0
Maxz=Posz+2
Nine=Numeric.ravel(Array3d[Posx, Miny:Maxy, Minz:Maxz])
MinNine=min(Nine)
EqMin=Numeric.equal(Nine,MinNine)
MinIndex=Numeric.nonzero(EqMin)
Index=whrandom.randint(0,len(MinIndice)-1)
MinIndex=MinIndex[Index]
if MinIndex==0:
Posy=Posy-1
Posz=Posz-1
elif MinIndex==1:
Posy=Posy
Posz=Posz-1
elif MinIndex==2:
Posy=Posy+1
Posz=Posz-1
elif MinIndex==3:
Posy=Posy-1
Posz=Posz
elif MinIndex==4:
Posy=Posy
Posz=Posz
elif MinIndex==5:
Posy=Posy+1
Posz=Posz
elif MinIndex==6:
Posy=Posy+1
Posz=Posz-1
elif MinIndex==7:
Posy=Posy+1
Posz=Posz
elif MinIndex==8:
Posy=Posy+1
Posz=Posz+1
now do something with "Array3d[Posx, Posy, Posz]"
TIA,
Ingo
--
Photography: http://members.home.nl/ingoogni/
Pov-Ray : http://members.home.nl/seed7/
More information about the Python-list
mailing list