Setup:
Emacs 25.2.1 on Windows 10
Pymacs 0.25
Anaconda Python 3.5.1
Pymacs is running fine. I can run pymacs-eval and pymacs-exec commands successfully from Emacs. For example, evaluating the following works:
(require 'pymacs)
(pymacs-exec "from scipy.stats import norm;")
(pymacs-exec "import numpy as np;")
(pymacs-exec "np.set_printoptions(threshold=np.nan);")
(pymacs-eval "norm.ppf(0.95)")
The last line returns
1.6448536269514722
The problem I am having is that some standard Python 3.x statements are returning something strange back to Emacs. In particular, if I run
(pymacs-eval "import numpy as np;")
(pymacs-eval "np.max(np.array([[1,1],[2,4]]))")
I get back
(pymacs-python . 1479)
If you run
(pymacs-load "numpy" "np-")
(np-max (np-array '((1 1) (2 4))))
The last line returns
(pymacs-python . 1479)
This seems to happen whenever I try passing any type of list from Emacs Lisp to Python via Pymacs. Does anybody know what these "(pymacs-python . n)" cons cells mean?
It took quite a bit of work to find the answer. The issue arises when Pymacs does not understand the structure produced by a particular Python function. In the case of Numpy, Pymacs has NO clue how to parse Numpy arrays. The trick is to convert the numpy arrays into standard Python lists.
Here is an example:
(require 'pymacs)
(pymacs-exec "import numpy as np")
(pymacs-eval "np.ndarray.tolist(np.asarray([[1,2],[3,4]]))")
This will produce
'((1 2) (3 4))
Sincerely,
Pablo
Related
I am looking for some direction to run Matlab in org-mode on a Win10 machine.
Matlab is installed and fully pathed within windows so it loads without issues.
Matlab is added in the org-babel languages list which loads without error.
These two lines to identify explicitely where matlab is and define header arguments which load without error.
(setq matlab-shell-command "c:/Program Files/MATLAB/R2018b/bin/matlab.exe")
(setq org-babel-default-header-args:matlab '((:results . "output") (:session . "*MATLAB*")))
When I attempt to run a something simple such as
#+begin_src matlab :results output
a=4
b=5
c=a*b
ans=c
#+end_src
I receive an error "no such file or directory, matlab".
What is the correct way to identify the location and execution of matlab to process the org-mode block?
(Note: I have extensively googled it but have not found any usable instruction from Win10 users who seem to be few in number.)
I've seen some applauses for org-babel in place of jupyter (https://news.ycombinator.com/item?id=16842786) and trying out what it is about.
I'd like to convert *.ipynb file to *.org file and the execute each source block in org mode as we would do in jupyter notebook.
(I tried ein couple of days, but it seems unstable)
I've succeeded converting file formats as illustrated in https://www.reddit.com/r/emacs/comments/7lcgkz/import_a_jupyter_notebook_to_an_orgmode_file/
However I'm having hard time executing code blocks because variables are not shared among code blocks.
Can I use PROPERTIES: or similar method to run them in the same context?
Can I use ipython?
I failed to google how to use org mode for ipynb file (as I try to do).
Would like to know if someone shares a work process of doing it
If variables are not shared between code blocks it might be due to the lack of :session argument otherwise each code block is run in standalone mode. For instance, the second block should print i
#+begin_src python :session my_session
i = 0
#+end_src
#+begin_src python :session my_session :results output
print(i)
#+end_src
whereas this one should raised a NameError: name 'i' is not defined error
#+begin_src python :results output
print(i)
#+end_src
I am running a script in ipython notebook (with Chrome) and noticed that it's 11 times slower than it is if I run the very same script in Python, using spyder as my IDE.
The script is quite simple: it's just a set of loops and calculations on a pandas dataframe. No output is printed to the screen nor written to external files. I expect the code to be slowish because it's not vectorised, I appreciate Ipython may involve some overhead, but 11 times... ! Can you think of any reasons why? Any suggestions?
Thanks!
I tested this on my machine, and found that ipython was actually faster.
$ cat ex.py
import time
import numpy as np
now = time.time() #(seconds)
a = []
for j in range(2):
for s in range(10):
a.append(np.random.random())
then = now
print(time.time() - then)
$ python ex.py
0.142902851105
In [1]: %run ex.py
0.06136202812194824
I bet it's the Chrome part of your ipython setup which is causing the slowdown.
I decided my birthday would be a good time to try and fix my Lisp problems.
I've received a Lisp program from someone to run an experiment. It works well on his OS X environment. However, I can't get it to run on either Windows 7 or Ubuntu. The program uses Act-R 6.2 to run a model. When I try to load the .lisp file I receive the following error:
:Reader error on #<BASIC-FILE-CHARACTER-INPUT-STREAM ("*path*"/28 UTF-8)#xCFAD1AE, near position 1048, within "smile* (#initWithCo":
Undefined character #\/ in a #\# dispatch macro.
While executing: CCL:SIGNAL-READER-ERROR, in process listener(1)
The error is the exact same for Windows 7 and Ubuntu. Here is the console output if it is required:
http://i.stack.imgur.com/dFXVm.png
It seems load-turing-application.lisp loads multiple other files, one of which is turing-application-v1.lisp, in which the line (setf *smile* (#/initWithContentsOfFile: (#/alloc ns:ns-image)(ccl::%make-nsstring "smiley.jpg")))
seems to be the culprit. I suspect it has something to do with the #/-notation.
Any ideas would be appreciated.
This is answered in the comments, but #/ is a CCL syntax that only is available on OS X. This code is not expected to work on linux or windows.
Using IPython .10-2, I can do the following from a python command line program:
from IPython.Shell import IPShellEmbed
IPShellEmbed(argv=[])()
This spawns an interactive IPython session at the point of invocation. I have been unable to find an equivalent for the .12 series of IPython.
Is there?
thanks, jim
The simplest way:
from IPython import embed
embed()
There's lots more info in the docs.