Skip to content

Instantly share code, notes, and snippets.

@axw
Created June 15, 2017 02:05
Show Gist options
  • Save axw/c257308e8fa241b957ea9a8763649373 to your computer and use it in GitHub Desktop.
Save axw/c257308e8fa241b957ea9a8763649373 to your computer and use it in GitHub Desktop.
Creating NumPy matrices/arrays from Java
public class Main {
public static void main(String []args) throws Exception {
pushy.Client client = new pushy.Client("local:", null);
try {
NumpyModule m = new NumpyModule(client);
System.out.println(m.array(m.mat("1 2; 3 4")));
} finally {
client.close();
}
}
}
class NumpyModule extends pushy.Module {
private final pushy.Client client;
private final pushy.PushyObject arrayMethod;
private final pushy.PushyObject matMethod;
public NumpyModule(pushy.Client client) {
super(client, "numpy");
this.client = client;
arrayMethod = __getmethod__("array");
matMethod = __getmethod__("mat");
}
public Object mat(String s) {
return matMethod.__call__(new Object[]{s});
}
public Object array(Object arg) {
return arrayMethod.__call__(new Object[]{arg});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment