@Test public void testNDArray() throws Exception{ Python.setContext("context1"); Python.exec("import numpy as np"); Python.exec("a = np.zeros((3,2)) + 1"); Python.setContext("context2"); Python.exec("import numpy as np"); Python.exec("a = np.zeros((3,2)) + 2"); Python.setContext("context3"); Python.exec("import numpy as np"); Python.exec("a = np.zeros((3,2)) + 3"); Python.setContext("context1"); Python.exec("a += 1"); Python.setContext("context2"); Python.exec("a += 2"); Python.setContext("context3"); Python.exec("a += 3"); INDArray arr = Nd4j.create(DataType.DOUBLE, 3, 2); Python.setContext("context1"); Assert.assertEquals(arr.add(2), PythonExecutioner.getVariable("a").toNumpy().getNd4jArray()); Python.setContext("context2"); Assert.assertEquals(arr.add(4), PythonExecutioner.getVariable("a").toNumpy().getNd4jArray()); Python.setContext("context3"); Assert.assertEquals(arr.add(6), PythonExecutioner.getVariable("a").toNumpy().getNd4jArray()); }
public static void setContext(String contextName) throws PythonException{ if (contextName.equals(currentContext)) { return; } if (!hasContext(contextName)) { addContext(contextName); } collapseContext(currentContext); expandContext(contextName); currentContext = contextName; }
PythonContextManager { public static void setContext(String contextName) throws PythonException{ if (contextName.equals(currentContext)) { return; } if (!hasContext(contextName)) { addContext(contextName); } collapseContext(currentContext); expandContext(contextName); currentContext = contextName; } }
PythonContextManager { public static void setContext(String contextName) throws PythonException{ if (contextName.equals(currentContext)) { return; } if (!hasContext(contextName)) { addContext(contextName); } collapseContext(currentContext); expandContext(contextName); currentContext = contextName; }  }
PythonContextManager { public static void setContext(String contextName) throws PythonException{ if (contextName.equals(currentContext)) { return; } if (!hasContext(contextName)) { addContext(contextName); } collapseContext(currentContext); expandContext(contextName); currentContext = contextName; }  static void addContext(String contextName); static boolean hasContext(String contextName); static boolean validateContextName(String s); static void setContext(String contextName); static void setMainContext(); static String getCurrentContext(); static void deleteContext(String contextName); static void deleteNonMainContexts(); String[] getContexts(); }
PythonContextManager { public static void setContext(String contextName) throws PythonException{ if (contextName.equals(currentContext)) { return; } if (!hasContext(contextName)) { addContext(contextName); } collapseContext(currentContext); expandContext(contextName); currentContext = contextName; }  static void addContext(String contextName); static boolean hasContext(String contextName); static boolean validateContextName(String s); static void setContext(String contextName); static void setMainContext(); static String getCurrentContext(); static void deleteContext(String contextName); static void deleteNonMainContexts(); String[] getContexts();  }