| 知乎专栏 |
// JDK 26 + Project Detroit
public class PythonIntegration {
public static void main(String[] args) {
try (var python = PythonRuntime.newRuntime()) {
// 直接调用numpy等Python库
PythonObject result = python.eval("""
import numpy as np
a = np.array([1,2,3,4,5])
a.mean()
""");
System.out.println("均值: " + result.toDouble());
}
}
}