Screenshot instructions:
Windows
Mac
Red Hat Linux
Ubuntu
Click URL instructions:
Rightclick on ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)
From: Alfonso Reyes <msfz751@re...>  20071014 12:00:08
Attachments:
Message as HTML

I was curious on how to work with jarray and move the arrays between classes after being filled with values and operated. I think this example explains some of the basics. Of course, there are more pythonic ways to do this. Cheers! Alfonso Reyes from java.lang import Math from jarray import array, zeros import java.util.Random; class ArrayClass: """ This class will fill an array with random numbers and then return the array for further operations """ def __init__(self, elems): self.N = elems systemEnergy = 0.0025 self.v = zeros(self.N, "d") # array of zeros, double type v0 = Math.sqrt(2.0 * systemEnergy / self.N) for i in range(0, self.N, 1): r = java.util.Random() self.v[i] = v0 * r.nextInt(self.N) # same velocity for all particles def out(self): for i in range(0, self.N, 1): print i, self.v[i] def get(self): return self.v n = 100 uarr = zeros(n, "d") # array of double to store some operations ac = ArrayClass(n) ac.out() # print the array arr = ac.get() # get the array to start doing some work on it # get a first third of the array members and times 10 print "Get a first third of the array members" for i in range(0, n/3, 1): uarr[i] = arr[i] * 10 print i, arr[i], uarr[i]  View this message in context: http://www.nabble.com/Arraysandclassesmixjustfine.JythonExamplestf4621491.html#a13198434 Sent from the jythonusers mailing list archive at Nabble.com. 
From: Josh Juneau <juneau001@gm...>  20071022 03:14:03

Alfonso, You've posted some nice code samples to the list. Can you add them to the wiki so that they will always be available for visitors? If so, that would be great! A good location would be: http://wiki.python.org/jython/DocumentationAndEducation Thanks  Josh Juneau juneau001@... http://jjblogger.blogspot.com On 10/14/07, Alfonso Reyes <msfz751@...> wrote: > I was curious on how to work with jarray and move the arrays between > classes after being filled with values and operated. I think this example > explains some of the basics. Of course, there are more pythonic ways to do > this. Cheers! Alfonso Reyes from java.lang import Math > from jarray import array, zeros > import java.util.Random; > > class ArrayClass: > """ This class will fill an array with random numbers > and then return the array for further operations > """ > def __init__(self, elems): > self.N = elems > systemEnergy = 0.0025 > self.v = zeros(self.N, "d") # array of zeros, double type > v0 = Math.sqrt(2.0 * systemEnergy / self.N) > for i in range(0, self.N, 1): > r = java.util.Random() > self.v[i] = v0 * r.nextInt(self.N) # same velocity for all particles > > def out(self): > for i in range(0, self.N, 1): > print i, self.v[i] > > def get(self): > return self.v > > n = 100 > uarr = zeros(n, "d") # array of double to store some operations > ac = ArrayClass(n) > ac.out() # print the array > arr = ac.get() # get the array to start doing some work on it > > # get a first third of the array members and times 10 > print "Get a first third of the array members" > for i in range(0, n/3, 1): > uarr[i] = arr[i] * 10 > print i, arr[i], uarr[i] > > > > ________________________________ > View this message in context: Arrays and classes mix just fine. Jython > Examples > Sent from the jythonusers mailing list archive at Nabble.com. > >  > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Jythonusers mailing list > Jythonusers@... > https://lists.sourceforge.net/lists/listinfo/jythonusers > > 
Sign up for the SourceForge newsletter:
No, thanks