<html><head><style type="text/css"><!-- DIV {margin:0px;} --></style></head><body><div style="font-family:times new roman,new york,times,serif;font-size:12pt"><div>Hi,<br><br>I am doing a little test using numpy and numexpr to do a particle simulation. I never used either of them much and this is the first time I have to go deeper. Here is the code:<br><br>import numpy as np<br>import numexpr as nexpr<br><br>class Particle( object ):<br>    <br>    def __init__( self, id ):<br>        self.position = [0.0, 0.0, 0.0]<br>        self.color = [0.5, 0.5, 0.5]<br>        self.direction = [0.0, 0.0, 0.0]<br>        self.id = id<br>        self.lifeSpan = 0<br>        self.type = 0<br><br>class Emitter( object
 ):<br>    <br>    def __init__( self ):<br>        self.particles = np.empty([], dtype=Particle())<br>        self.currentParticleId = 0<br>        self.numParticles = 1000<br>        self.emissionRate = 10<br>        self.position = [0.0, 0.0, 0.0]<br>        self.rotation = [0.0, 0.0, 0.0]<br>        <br>    # Add a single particle<br>    def addParticle( self ):<br>        """<br>        Add a single particle in the emitter.<br>        """<br>        if self.currentParticleId <
 self.numParticles:<br>            self.particles = np.append( self.particles, Particle( self..currentParticleId ) )<br>            self.currentParticleId+=1   <br><br><br>#######################################################<br>Problem 1:<br>self.particles = np.empty([], dtype=Particle())<br>In "Emitter" class, how do I initialize a numpy array of "Particle" type?<br><br>Problem 2:<br>If problem 1 can be solved, is it possible to use numexpr to alter the position of each particle's position<br>in emitter.particles array. For example, multiply x,y and z of each particle by using three random values. In other words<br><br>self.particles[0].position*= random(1.0)<br>self.particles[1].position*= random(2.0)<br>self.particles[2].position*= random(3.0)<br><br>If problem 1 cannot be solved then may be I could use something like this using
 simple list:<br><br>a = [Particle(0), Particle(1)]<br><br>How do I modify the position of each particle in array"a" using numexpr?<br><br>I would be using 1-5 million particles where each particle's attribute postion, rotation and color will be modified using some complex<br>equations. The above code is just the begining hence any tips for performance would be greatly apperciated.<br><br>Regards<br><br>Prashant<br><br><br></div></div><br>



      <!--3--><hr size=1></hr> Looking for local information? Find it on <a href="http://in.rd.yahoo.com/tagline_local_1/*http://in.local..yahoo.com/" target="_blank"> Yahoo! Local</a></body></html>