title: Fast conversion of Java array to NumPy array (Py4J)
body: <p>There are some nice examples how to convert NumPy array to Java array, but not vice versa - how to convert data from Java object back to NumPy array. I have a Python script like this:</p>
  
  <pre><code>    from py4j.java_gateway import JavaGateway
      gateway = JavaGateway()            # connect to the JVM
      my_java = gateway.jvm.JavaClass();  # my Java object
      ....
      int_array=my_java.doSomething(int_array); # do something
  
      my_numpy=np.zeros((size_y,size_x));
      for jj in range(size_y):
          for ii in range(size_x):
              my_numpy[jj,ii]=int_array[jj][ii];
  </code></pre>
  
  <p><code>my_numpy</code> is the Numpy array, <code>int_array</code> is the Java array of integers - <code>int[ ][ ]</code> kind of array. Initialized in Python script as:</p>
  
  <pre><code>    int_class=gateway.jvm.int       # make int class
      double_class=gateway.jvm.double # make double class
  
      int_array = gateway.new_array(int_class,size_y,size_x)
      double_array = gateway.new_array(double_class,size_y,size_x)
  </code></pre>
  
  <p>Although, it works as it is, it is not the fastest way and works rather slowly - for ~1000x1000 array, the conversion took more than 5 minutes. </p>
  
  <p>Is there any way how to make this with reasonable time?</p>
  
  <p>If I try:</p>
  
  <pre><code>    test=np.array(int_array)
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>    ValueError: invalid __array_struct__
  </code></pre>