jkitchin / pycse

Python computations in science and engineering
GNU General Public License v2.0
245 stars 68 forks source link

Using org-table data within an ipython block #26

Closed Arjay-El closed 6 years ago

Arjay-El commented 6 years ago

Question. not an issue: Do you have an explicit example from your work in which you have created a table in org mode and then called various numbers in that table from within an ipython block? I looked at the examples in pycse but do not see one in which a table in org was accessed from an ipython or python babel block for numerical data this manner. The Mail merge example was close but I could not decipher it in a way to access a table of numerical data successfully. Perhaps a reference to a paper you have written?

jkitchin commented 6 years ago

You mean like this?

#+name: data
| x | y |
|---+---|
| 2 | 3 |
| 4 | 5 |

The variable d below is a list:

#+BEGIN_SRC ipython :var d=data
d[1][1]
#+END_SRC

#+RESULTS:
:RESULTS:
# Out[2]:
# text/plain
: 5
:END:

You can cast it as an array to make array slicing easier.

#+BEGIN_SRC ipython
import numpy as np

d = np.array(d)
d[:, 1]
#+END_SRC

#+RESULTS:
:RESULTS:
# Out[3]:
# text/plain
: array([3, 5])
:END:
Arjay-El commented 6 years ago

Exactly John, clearest example I have seen in all my googling for it.. Much appreciated,