Differences between revisions 4 and 5
Revision 4 as of 2014-05-10 04:43:56
Size: 437
Editor: S8885
Comment:
Revision 5 as of 2014-05-11 02:11:18
Size: 1743
Editor: AdamBurke
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Hey there Lurked for ages, finally decided to sign up... thank you for viewing my profile (!) (hope you aren't a stalker !!!!!). By the way sorry for my terrible English..., I'm still learning it. <<BR>>
"We are all in the gutter, but some of us are looking at the stars."<<BR>>
<<BR>>
Feel free to surf to my homepage [[http://www.lafeiwang.com/space.php?uid=141412&do=blog&id=789077|black diamond engagement and Wedding band set]]
#format wiki
#language en
#pragma section-numbers off

= Using Java Classes in Jython =

DocumentationAndEducation

<<TableOfContents>>

----

=== Array ===
Posted to the Jython-users mailing list by Alfonso Reyes on October 14, 2007<<BR>>

Here is an example of a 3D array. I am not fully satisfied with this implementation but to anybody starting with Jython and Java arrays will clarify lots of things.

To do:<<BR>>
- the class should automatically instantiate and return the array<<BR>>
- a print method that can print the class or any arrays operating outside the class

{{{#!python
""" 3D array with class

"""
from java.lang.reflect import Array
import java

class multi:
    def __init__(self, i, j, k):
        self.m = i; self.n = j; self.p = k
        self.arr = Array.newInstance(java.lang.Double.TYPE, [self.m, self.n, self.p] )

    def get(self):
        return self.arr

    def out(self):
        print "printing multidimensional array inside class"
        for i in range(0, self.m, 1):
            for j in range(0, self.n, 1):
                for k in range(0, self.p,1):
                    print self.arr[i][j][k],
                print
            print
        print


def out(arr,m,n,p):
    # TO-DO: one method that can print a class-array and a bare array
    print "printing multidimensional array"
    for i in range(0, m, 1):
        for j in range(0, n, 1):
            for k in range(0, p,1):
                print arr[i][j][k],
            print
        print
    print


tArr = multi(4,3,5)
uArr = tArr.get()

print uArr
tArr.out()
uArr[0][0][0] = 7.77
uArr[3][2][4] = 7.77
out(uArr,4,3,5) # read what the array contains

}}}

Using Java Classes in Jython

DocumentationAndEducation


Array

Posted to the Jython-users mailing list by Alfonso Reyes on October 14, 2007

Here is an example of a 3D array. I am not fully satisfied with this implementation but to anybody starting with Jython and Java arrays will clarify lots of things.

To do:
- the class should automatically instantiate and return the array
- a print method that can print the class or any arrays operating outside the class

   1 """     3D array with class
   2 
   3 """
   4 from java.lang.reflect import Array
   5 import java
   6 
   7 class multi:
   8     def __init__(self, i, j, k):
   9         self.m = i; self.n = j; self.p = k
  10         self.arr = Array.newInstance(java.lang.Double.TYPE, [self.m, self.n, self.p] )
  11 
  12     def get(self):
  13         return self.arr
  14 
  15     def out(self):
  16         print "printing multidimensional array inside class"
  17         for i in range(0, self.m, 1):
  18             for j in range(0, self.n, 1):
  19                 for k in range(0, self.p,1):
  20                     print self.arr[i][j][k],
  21                 print
  22             print
  23         print
  24 
  25 
  26 def out(arr,m,n,p):
  27     # TO-DO: one method that can print a class-array and a bare array
  28     print "printing multidimensional array"
  29     for i in range(0, m, 1):
  30         for j in range(0, n, 1):
  31             for k in range(0, p,1):
  32                 print arr[i][j][k],
  33             print
  34         print
  35     print
  36 
  37 
  38 tArr = multi(4,3,5)
  39 uArr = tArr.get()
  40 
  41 print uArr
  42 tArr.out()
  43 uArr[0][0][0] = 7.77
  44 uArr[3][2][4] = 7.77
  45 out(uArr,4,3,5)        # read what the array contains

JavaLibraries (last edited 2014-05-11 02:11:18 by AdamBurke)