Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

How to call python function in java?

$
0
0

I have a python function as the following

from sklearn.preprocessing import QuantileTransformerimport numpy as npdef fit_transform(fitting_matrix, new_matrix):    transformer = QuantileTransformer(output_distribution='uniform')    transformer.fit(fitting_matrix)    return transformer.transform(new_matrix)if __name__ == '__main__':    # Generating some sample data    matrix_one = np.random.rand(100, 1) * 10    matrix_two = np.random.rand(10, 1) * 10    print(fit_transform(matrix_one, matrix_two))

The above function receives a fitting_matrix to fit the QuantileTransformer and receives another matrix new_matrix to be transformed.

Now I want to call the fit_transform function in Java.And I have asked chatgpt, and chatgpt suggested the following method

  1. JNI
  2. JNA
  3. package python file into .so file and call that .so file in java

None of the above three methods work. So, please, How to call the above python function in java?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>