<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.lptms.universite-paris-saclay.fr//wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Landes</id>
	<title>LPTMS Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.lptms.universite-paris-saclay.fr//wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Landes"/>
	<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php/Special:Contributions/Landes"/>
	<updated>2026-04-15T03:53:43Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Reading_a_large_data_file_(efficiently)&amp;diff=407</id>
		<title>Reading a large data file (efficiently)</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Reading_a_large_data_file_(efficiently)&amp;diff=407"/>
		<updated>2014-02-16T18:23:52Z</updated>

		<summary type="html">&lt;p&gt;Landes: j&amp;#039;ai expliqué comment utiliser with open pour obtenir toute une matrice de donnees, mais de facon rapide. Et aussi un mot sur l&amp;#039;utilisation du module &amp;quot;subprocess&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Reading large data files can quickly become a trouble.&lt;br /&gt;
&lt;br /&gt;
np.loadtxt(&#039;filename&#039;) allows an easy conversion of the file to an array, but it is unpractical, in particular if your data file size exceeds your RAM.&lt;br /&gt;
&lt;br /&gt;
An other, much more efficient way (with the appropriate buffers, etc. handled by python) is using &amp;quot;with open(...) as file&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
N=10000000&lt;br /&gt;
bigMatrix = np.zeros((N, 12))      # same shape as the expected data. Here, we have 12 columns. &lt;br /&gt;
                                   # With this N , &amp;quot;bigMatrix&amp;quot; is more or less 1 GB large.&lt;br /&gt;
iteration = 0&lt;br /&gt;
with open(filename, &#039;r&#039;) as f:    # this is an efficient way of handling the file.&lt;br /&gt;
    for line in f:&lt;br /&gt;
        bigMatrix[iteration] = np.fromstring(line, sep=&#039; &#039;)  # if the column separator is a space &amp;quot; &amp;quot;. Adapt otherwise.&lt;br /&gt;
        iteration +=1&lt;br /&gt;
        if iteration &amp;gt;= N:  # in order not to exceed the matrix size, if the data is longer than N.&lt;br /&gt;
            break&lt;br /&gt;
bigMatrix =  bigMatrix[:iteration, :]     # in order not to have leftover zeros, if the data is shorter than N.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
the only limitation is that you need to specify a shape (esp. the column number) in advance, but usually if you want to analyze many files with some format that you invented, this should not be a problem.&lt;br /&gt;
&lt;br /&gt;
A possible way to circumvent the problem of choosing N in advance is to run something like &lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
import subprocess&lt;br /&gt;
output_string = subprocess.check_output([&#039;wc -l my_data_file_name.dat&#039;], shell=True)&lt;br /&gt;
number_of_lines_in_file = np.fromstring(output_string, sep=&#039; &#039;)[0]&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
and then use the resulting line count as N.&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=406</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=406"/>
		<updated>2014-02-16T17:43:38Z</updated>

		<summary type="html">&lt;p&gt;Landes: J&amp;#039;ajoute une petite rubrique sur la lecture de gros fichiers en python&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.python.org Official website]&lt;br /&gt;
* [http://www.euroscipy.org euroscipy] (scientific python community)&lt;br /&gt;
* [http://scipy-lectures.github.com Getting started with scipy]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique] - Voir aussi Cython.&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]&lt;br /&gt;
&lt;br /&gt;
== Libraries and softwares ==&lt;br /&gt;
&lt;br /&gt;
* [http://ipython.org iPython]&lt;br /&gt;
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.&lt;br /&gt;
* [http://docs.python.org/library Standard Library]&lt;br /&gt;
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]&lt;br /&gt;
* [http://matplotlib.sourceforge.net Matplotlib]&lt;br /&gt;
* [http://sympy.org SymPy]&lt;br /&gt;
* [http://cython.org Cython]&lt;br /&gt;
* [http://www.pytables.org PyTables]&lt;br /&gt;
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]&lt;br /&gt;
* [http://pypy.org/ PyPy], a just-in-time compiler/implementation of Python.&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
* [http://fperez.org/code/index.html Fernando Perez page on Python]&lt;br /&gt;
* [[Interfacing C++ and Python]]. &lt;br /&gt;
* [http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html Interfacing Python and C++] (the other way around). See also Cython, below.&lt;br /&gt;
* [[Scientific Programming with Python (for the debug), and C(ython) for the speed]]&lt;br /&gt;
* [[Fitting data with python]]&lt;br /&gt;
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]&lt;br /&gt;
* [[Quick integration of a known function]]&lt;br /&gt;
* [[Reading a large data file (efficiently)]]&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* equivalent of the C ternary operator ?: (&#039;&#039;bool&#039;&#039; ? &#039;&#039;restrue&#039;&#039; : &#039;resfalse&#039;&#039;), use a tuple&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
(resfalse,restrue)[bool]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* adding a path to a directory containing your module files&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path += [ &amp;quot;/home/username/bin/Python&amp;quot; ]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* test whether a string has only digits or letters&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
str = &#039;1321&#039;&lt;br /&gt;
str.isdigit() # returns True/False&lt;br /&gt;
str.isalpha() # returns True/False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Nested for loops in a single line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:&lt;br /&gt;
    print n,m&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=405</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=405"/>
		<updated>2013-11-15T15:00:47Z</updated>

		<summary type="html">&lt;p&gt;Landes: /* Libraries and softwares */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.python.org Official website]&lt;br /&gt;
* [http://www.euroscipy.org euroscipy] (scientific python community)&lt;br /&gt;
* [http://scipy-lectures.github.com Getting started with scipy]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique] - Voir aussi Cython.&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]&lt;br /&gt;
&lt;br /&gt;
== Libraries and softwares ==&lt;br /&gt;
&lt;br /&gt;
* [http://ipython.org iPython]&lt;br /&gt;
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.&lt;br /&gt;
* [http://docs.python.org/library Standard Library]&lt;br /&gt;
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]&lt;br /&gt;
* [http://matplotlib.sourceforge.net Matplotlib]&lt;br /&gt;
* [http://sympy.org SymPy]&lt;br /&gt;
* [http://cython.org Cython]&lt;br /&gt;
* [http://www.pytables.org PyTables]&lt;br /&gt;
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]&lt;br /&gt;
* [http://pypy.org/ PyPy], a just-in-time compiler/implementation of Python.&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
* [http://fperez.org/code/index.html Fernando Perez page on Python]&lt;br /&gt;
* [[Interfacing C++ and Python]]. &lt;br /&gt;
* [http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html Interfacing Python and C++] (the other way around). See also Cython, below.&lt;br /&gt;
* [[Scientific Programming with Python (for the debug), and C(ython) for the speed]]&lt;br /&gt;
* [[Fitting data with python]]&lt;br /&gt;
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]&lt;br /&gt;
* [[Quick integration of a known function]]&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* equivalent of the C ternary operator ?: (&#039;&#039;bool&#039;&#039; ? &#039;&#039;restrue&#039;&#039; : &#039;resfalse&#039;&#039;), use a tuple&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
(resfalse,restrue)[bool]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* adding a path to a directory containing your module files&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path += [ &amp;quot;/home/username/bin/Python&amp;quot; ]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* test whether a string has only digits or letters&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
str = &#039;1321&#039;&lt;br /&gt;
str.isdigit() # returns True/False&lt;br /&gt;
str.isalpha() # returns True/False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Nested for loops in a single line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:&lt;br /&gt;
    print n,m&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=404</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=404"/>
		<updated>2013-11-15T14:53:53Z</updated>

		<summary type="html">&lt;p&gt;Landes: /* Miscellaneous */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.python.org Official website]&lt;br /&gt;
* [http://www.euroscipy.org euroscipy] (scientific python community)&lt;br /&gt;
* [http://scipy-lectures.github.com Getting started with scipy]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique] - Voir aussi Cython.&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]&lt;br /&gt;
&lt;br /&gt;
== Libraries and softwares ==&lt;br /&gt;
&lt;br /&gt;
* [http://ipython.org iPython]&lt;br /&gt;
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.&lt;br /&gt;
* [http://docs.python.org/library Standard Library]&lt;br /&gt;
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]&lt;br /&gt;
* [http://matplotlib.sourceforge.net Matplotlib]&lt;br /&gt;
* [http://sympy.org SymPy]&lt;br /&gt;
* [http://cython.org Cython]&lt;br /&gt;
* [http://www.pytables.org PyTables]&lt;br /&gt;
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
* [http://fperez.org/code/index.html Fernando Perez page on Python]&lt;br /&gt;
* [[Interfacing C++ and Python]]. &lt;br /&gt;
* [http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html Interfacing Python and C++] (the other way around). See also Cython, below.&lt;br /&gt;
* [[Scientific Programming with Python (for the debug), and C(ython) for the speed]]&lt;br /&gt;
* [[Fitting data with python]]&lt;br /&gt;
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]&lt;br /&gt;
* [[Quick integration of a known function]]&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* equivalent of the C ternary operator ?: (&#039;&#039;bool&#039;&#039; ? &#039;&#039;restrue&#039;&#039; : &#039;resfalse&#039;&#039;), use a tuple&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
(resfalse,restrue)[bool]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* adding a path to a directory containing your module files&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path += [ &amp;quot;/home/username/bin/Python&amp;quot; ]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* test whether a string has only digits or letters&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
str = &#039;1321&#039;&lt;br /&gt;
str.isdigit() # returns True/False&lt;br /&gt;
str.isalpha() # returns True/False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Nested for loops in a single line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:&lt;br /&gt;
    print n,m&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Scientific_Programming_with_Python_(for_the_debug),_and_C(ython)_for_the_speed&amp;diff=403</id>
		<title>Scientific Programming with Python (for the debug), and C(ython) for the speed</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Scientific_Programming_with_Python_(for_the_debug),_and_C(ython)_for_the_speed&amp;diff=403"/>
		<updated>2013-11-14T14:39:17Z</updated>

		<summary type="html">&lt;p&gt;Landes: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;With Cython, one can finally use Python and obtain near C-like performance. This is especially valuable if you have to start a project from scratch.&lt;br /&gt;
&lt;br /&gt;
There is actually a [http://docs.cython.org/src/userguide/numpy_tutorial.html tutorial for Numpy users] which is pretty well done. Here the main steps of the cythonization process are summarized, as a teaser-guide.&lt;br /&gt;
&lt;br /&gt;
If you are not convinced by the final speed one can obtain with Cython, there are some [http://technicaldiscovery.blogspot.com.ar/2011/06/speeding-up-python-numpy-cython-and.html benchmarks] on the web, and also the [http://docs.cython.org/src/tutorial/profiling_tutorial.html Cython profiling tutorial].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The methodology is outlined here, with a focus on the important details:&lt;br /&gt;
&lt;br /&gt;
- Write your code in pure Python. It is very easy, so you can play with it, think about the best algorithm to implement your problem, etc. Use iPython for debugging (you can access and modify variables at run time after an error occurred).&lt;br /&gt;
 &lt;br /&gt;
- Remove all the use of Python-specific data containers like sets, dicts, lists. Instead, use numpy arrays. &lt;br /&gt;
&lt;br /&gt;
- Do not use vectorial operations, instead, use loops, as you would do in C/C++. This is highly UN-efficient in Numpy, but it is what you need for Cython.&lt;br /&gt;
&lt;br /&gt;
Your code is now very slow, because you use loops in Python/Numpy, which is deprecated, and because the Python is overloaded with tons of background checks, and allows dynamic typing (more checks to be done at execution time).&lt;br /&gt;
&lt;br /&gt;
- Cythonize it ! You have to create a setup.py file, copy-paste the bulk of your original code in some main() function of some .pyx file. (This is explained very well [http://docs.cython.org/0.15/src/userguide/tutorial.html Cython Hello World]. (Hint: to indent a block of text, you can usually select it (even hundreds of lines) and hit Tab, e.g. in gedit).&lt;br /&gt;
&lt;br /&gt;
Your code is now compiled in Cython, wrapped in some main() function (plus additional functions if you have some). It is still very slow, because the .c file created does all the usual Python checks. &lt;br /&gt;
&lt;br /&gt;
- Do $ cython -a your_pyx_file.pyx . Open the html document produced: the yellow indicates how much the Python API is called. You can click on each line to see the C implementation and the details of the PyAPI calls.&lt;br /&gt;
&lt;br /&gt;
- Type all the core variables, especially the arrays you use. You can use profiling tools, but first you should try to take off all the API calls you can. When there is no more yellow in the main loop of your code, you should be fine, if your algorithm (independently form the language) is well designed.&lt;br /&gt;
&lt;br /&gt;
- Deactivate the boundscheck and wraparound when debugging is over: Add &lt;br /&gt;
\#cython: boundscheck=False  &lt;br /&gt;
\#cython: wraparound=False&lt;br /&gt;
in your code, before any code or whitespace (but there can be some comments before).&lt;br /&gt;
&lt;br /&gt;
Your code is now almost as fast as C, and you saved a lot of debugging time ! The sytax is that of Python, except for the declarations of variables (using cdef). I at some point you need to go back to a debugging-friendly environment, you can always copy-paste your pyx file in .py file, comment all the declarations, and work with the python code. &lt;br /&gt;
&lt;br /&gt;
Since Cython compiles the code with the --fno-strict-aliasing option, performance is not very far from Fortran either.&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=402</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=402"/>
		<updated>2013-11-14T14:29:21Z</updated>

		<summary type="html">&lt;p&gt;Landes: /* Miscellaneous */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.python.org Official website]&lt;br /&gt;
* [http://www.euroscipy.org euroscipy] (scientific python community)&lt;br /&gt;
* [http://scipy-lectures.github.com Getting started with scipy]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique] - Voir aussi Cython.&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]&lt;br /&gt;
&lt;br /&gt;
== Libraries and softwares ==&lt;br /&gt;
&lt;br /&gt;
* [http://ipython.org iPython]&lt;br /&gt;
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.&lt;br /&gt;
* [http://docs.python.org/library Standard Library]&lt;br /&gt;
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]&lt;br /&gt;
* [http://matplotlib.sourceforge.net Matplotlib]&lt;br /&gt;
* [http://sympy.org SymPy]&lt;br /&gt;
* [http://cython.org Cython]&lt;br /&gt;
* [http://www.pytables.org PyTables]&lt;br /&gt;
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
* [http://fperez.org/code/index.html Fernando Perez page on Python]&lt;br /&gt;
* [[Interfacing C++ and Python]]. See also [http://docs.scipy.org/doc/numpy/user/c-info.python-as-glue.html Python as glue] and the page below about Cython.&lt;br /&gt;
* [[Scientific Programming with Python (for the debug), and C(ython) for the speed]]&lt;br /&gt;
* [[Fitting data with python]]&lt;br /&gt;
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]&lt;br /&gt;
* [[Quick integration of a known function]]&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* equivalent of the C ternary operator ?: (&#039;&#039;bool&#039;&#039; ? &#039;&#039;restrue&#039;&#039; : &#039;resfalse&#039;&#039;), use a tuple&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
(resfalse,restrue)[bool]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* adding a path to a directory containing your module files&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path += [ &amp;quot;/home/username/bin/Python&amp;quot; ]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* test whether a string has only digits or letters&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
str = &#039;1321&#039;&lt;br /&gt;
str.isdigit() # returns True/False&lt;br /&gt;
str.isalpha() # returns True/False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Nested for loops in a single line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:&lt;br /&gt;
    print n,m&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Scientific_Programming_with_Python_(for_the_debug),_and_C(ython)_for_the_speed&amp;diff=401</id>
		<title>Scientific Programming with Python (for the debug), and C(ython) for the speed</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Scientific_Programming_with_Python_(for_the_debug),_and_C(ython)_for_the_speed&amp;diff=401"/>
		<updated>2013-11-14T14:12:23Z</updated>

		<summary type="html">&lt;p&gt;Landes: Created page with &amp;quot;With Cython, one can finally use Python and obtain near C-like performance. This is especially valuable if you have to start a project from scratch.  There is actually a [http...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;With Cython, one can finally use Python and obtain near C-like performance. This is especially valuable if you have to start a project from scratch.&lt;br /&gt;
&lt;br /&gt;
There is actually a [http://docs.cython.org/src/userguide/numpy_tutorial.html tutorial for Numpy users] which is pretty well done. Here the main steps of the cythonization process are summarized, as a teaser-guide.&lt;br /&gt;
&lt;br /&gt;
If you are not convinced by the final speed one can obtain with Cython, there are some benchmarks on the web, and also [http://docs.cython.org/src/tutorial/profiling_tutorial.html Cython profiling tutorial].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The methodology is the following:&lt;br /&gt;
&lt;br /&gt;
- Write your code in pure Python. It is very easy, so you can play with it, think about the best algorithm to implement your problem, etc. Use iPython for debugging (you can access and modify variables at run time after an error occurred).&lt;br /&gt;
 &lt;br /&gt;
- Remove all the use of Python-specific data containers like sets, dicts, lists. Instead, use numpy arrays. &lt;br /&gt;
&lt;br /&gt;
- Do not use vectorial operations, instead, use loops, as you would do in C/C++. This is highly UN-efficient in Numpy, but it is what you need for Cython.&lt;br /&gt;
&lt;br /&gt;
Your code is now very slow, because you use loops in Python/Numpy, which is deprecated, and because the Python is overloaded with tons of background checks, and allows dynamic typing (more checks to be done at execution time).&lt;br /&gt;
&lt;br /&gt;
- Cythonize it ! You have to create a setup.py file, copy-paste the bulk of your original code in some main() function of some .pyx file. (This is explained very well [http://docs.cython.org/0.15/src/userguide/tutorial.html Cython Hello World]. (Hint: to indent a block of text, you can usually select it (even hundreds of lines) and hit Tab, e.g. in gedit).&lt;br /&gt;
&lt;br /&gt;
Your code is now compiled in Cython, wrapped in some main() function (plus additional functions if you have some). It is still very slow, because the .c file created does all the usual Python checks. &lt;br /&gt;
&lt;br /&gt;
- Do $ cython -a your_pyx_file.pyx . Open the html document produced: the yellow indicates how much the Python API is called. You can click on each line to see the C implementation and the details of the PyAPI calls.&lt;br /&gt;
&lt;br /&gt;
- Type all the core variables, especially the arrays you use. You can use profiling tools, but first you should try to take off all the API calls you can. When there is no more yellow in the main loop of your code, you should be fine, if your algorithm (independently form the language) is well designed.&lt;br /&gt;
&lt;br /&gt;
- Deactivate the boundscheck and wraparound when debugging is over. &lt;br /&gt;
&lt;br /&gt;
Your code is now almost as fast as C, and you saved a lot of debugging time ! Since Cython compiles the code with the --fno-strict-aliasing option, performance is not very far from Fortran either.&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=400</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=400"/>
		<updated>2013-11-14T13:47:39Z</updated>

		<summary type="html">&lt;p&gt;Landes: /* Miscellaneous */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.python.org Official website]&lt;br /&gt;
* [http://www.euroscipy.org euroscipy] (scientific python community)&lt;br /&gt;
* [http://scipy-lectures.github.com Getting started with scipy]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique] - Voir aussi Cython.&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]&lt;br /&gt;
&lt;br /&gt;
== Libraries and softwares ==&lt;br /&gt;
&lt;br /&gt;
* [http://ipython.org iPython]&lt;br /&gt;
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.&lt;br /&gt;
* [http://docs.python.org/library Standard Library]&lt;br /&gt;
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]&lt;br /&gt;
* [http://matplotlib.sourceforge.net Matplotlib]&lt;br /&gt;
* [http://sympy.org SymPy]&lt;br /&gt;
* [http://cython.org Cython]&lt;br /&gt;
* [http://www.pytables.org PyTables]&lt;br /&gt;
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
* [http://fperez.org/code/index.html Fernando Perez page on Python]&lt;br /&gt;
* [[Interfacing C++ and Python]]&lt;br /&gt;
* [[Scientific Programming with Python (for the debug), and C(ython) for the speed]]&lt;br /&gt;
* [[Fitting data with python]]&lt;br /&gt;
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]&lt;br /&gt;
* [[Quick integration of a known function]]&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* equivalent of the C ternary operator ?: (&#039;&#039;bool&#039;&#039; ? &#039;&#039;restrue&#039;&#039; : &#039;resfalse&#039;&#039;), use a tuple&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
(resfalse,restrue)[bool]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* adding a path to a directory containing your module files&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path += [ &amp;quot;/home/username/bin/Python&amp;quot; ]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* test whether a string has only digits or letters&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
str = &#039;1321&#039;&lt;br /&gt;
str.isdigit() # returns True/False&lt;br /&gt;
str.isalpha() # returns True/False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Nested for loops in a single line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:&lt;br /&gt;
    print n,m&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=399</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=399"/>
		<updated>2013-11-14T13:43:00Z</updated>

		<summary type="html">&lt;p&gt;Landes: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.python.org Official website]&lt;br /&gt;
* [http://www.euroscipy.org euroscipy] (scientific python community)&lt;br /&gt;
* [http://scipy-lectures.github.com Getting started with scipy]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique] - Voir aussi Cython.&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]&lt;br /&gt;
&lt;br /&gt;
== Libraries and softwares ==&lt;br /&gt;
&lt;br /&gt;
* [http://ipython.org iPython]&lt;br /&gt;
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.&lt;br /&gt;
* [http://docs.python.org/library Standard Library]&lt;br /&gt;
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]&lt;br /&gt;
* [http://matplotlib.sourceforge.net Matplotlib]&lt;br /&gt;
* [http://sympy.org SymPy]&lt;br /&gt;
* [http://cython.org Cython]&lt;br /&gt;
* [http://www.pytables.org PyTables]&lt;br /&gt;
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
* [http://fperez.org/code/index.html Fernando Perez page on Python]&lt;br /&gt;
* [[Interfacing C++ and Python]]&lt;br /&gt;
* [[Fitting data with python]]&lt;br /&gt;
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]&lt;br /&gt;
* [[Quick integration of a known function]]&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* equivalent of the C ternary operator ?: (&#039;&#039;bool&#039;&#039; ? &#039;&#039;restrue&#039;&#039; : &#039;resfalse&#039;&#039;), use a tuple&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
(resfalse,restrue)[bool]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* adding a path to a directory containing your module files&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path += [ &amp;quot;/home/username/bin/Python&amp;quot; ]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* test whether a string has only digits or letters&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
str = &#039;1321&#039;&lt;br /&gt;
str.isdigit() # returns True/False&lt;br /&gt;
str.isalpha() # returns True/False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Nested for loops in a single line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:&lt;br /&gt;
    print n,m&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=GPU&amp;diff=398</id>
		<title>GPU</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=GPU&amp;diff=398"/>
		<updated>2013-11-14T13:40:47Z</updated>

		<summary type="html">&lt;p&gt;Landes: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;* [http://www.khronos.org/opencl OpenCL]&lt;br /&gt;
* [http://www.nvidia.fr/object/cuda-parallel-computing-fr.html CUDA] (Nvidia-specific, more user-friendly than OpenCL)&lt;br /&gt;
* [http://mathema.tician.de/software/pycuda/ PyCUDA] (Nvidia-specific) Wrapping CUDA into Python.&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=397</id>
		<title>Python</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Python&amp;diff=397"/>
		<updated>2013-11-14T13:36:50Z</updated>

		<summary type="html">&lt;p&gt;Landes: /* documentation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== documentation ==&lt;br /&gt;
&lt;br /&gt;
* [http://www.python.org Official website]&lt;br /&gt;
* [http://www.euroscipy.org euroscipy] (scientific python community)&lt;br /&gt;
* [http://scipy-lectures.github.com Getting started with scipy]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-comme-langage-scientifique Python comme langage scientifique]&lt;br /&gt;
* [http://www.unixgarden.com/index.php/programmation/python-et-le-c Python et le C]&lt;br /&gt;
&lt;br /&gt;
== Libraries and softwares ==&lt;br /&gt;
&lt;br /&gt;
* [http://ipython.org iPython]&lt;br /&gt;
* [http://ipython.org/ipython-doc/dev/interactive/htmlnotebook.html the iPython notebook] (interface similar to Mathematica) use HTML to handle worksheets.&lt;br /&gt;
* [http://docs.python.org/library Standard Library]&lt;br /&gt;
* [http://scipy.org SciPy] - [http://numpy.scipy.org NumPy]&lt;br /&gt;
* [http://matplotlib.sourceforge.net Matplotlib]&lt;br /&gt;
* [http://sympy.org SymPy]&lt;br /&gt;
* [http://cython.org Cython]&lt;br /&gt;
* [http://www.pytables.org PyTables]&lt;br /&gt;
* [http://mdp-toolkit.sourceforge.net/ Modular toolkit for Data Processing]&lt;br /&gt;
&lt;br /&gt;
== Miscellaneous ==&lt;br /&gt;
&lt;br /&gt;
* [http://fperez.org/code/index.html Fernando Perez page on Python]&lt;br /&gt;
* [[Interfacing C++ and Python]]&lt;br /&gt;
* [[Fitting data with python]]&lt;br /&gt;
* [http://code.enthought.com/projects/mayavi/ 3D Scientific Data Visualization and Plotting]&lt;br /&gt;
* [[Quick integration of a known function]]&lt;br /&gt;
&lt;br /&gt;
== Tips ==&lt;br /&gt;
&lt;br /&gt;
* equivalent of the C ternary operator ?: (&#039;&#039;bool&#039;&#039; ? &#039;&#039;restrue&#039;&#039; : &#039;resfalse&#039;&#039;), use a tuple&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
(resfalse,restrue)[bool]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* adding a path to a directory containing your module files&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
import sys&lt;br /&gt;
sys.path += [ &amp;quot;/home/username/bin/Python&amp;quot; ]&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* test whether a string has only digits or letters&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
str = &#039;1321&#039;&lt;br /&gt;
str.isdigit() # returns True/False&lt;br /&gt;
str.isalpha() # returns True/False&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Nested for loops in a single line:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;py&amp;quot;&amp;gt;&lt;br /&gt;
for n,m in [ (n,m) for n in range(10) for m in range(2) ]:&lt;br /&gt;
    print n,m&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
	<entry>
		<id>http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Managing_bibliography&amp;diff=396</id>
		<title>Managing bibliography</title>
		<link rel="alternate" type="text/html" href="http://www.lptms.universite-paris-saclay.fr//wiki/index.php?title=Managing_bibliography&amp;diff=396"/>
		<updated>2013-11-14T13:35:20Z</updated>

		<summary type="html">&lt;p&gt;Landes: /* Reference management softwares */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Reference management softwares==&lt;br /&gt;
&lt;br /&gt;
[http://jabref.sourceforge.net JabRef] is a java - OS independent - free software. It works directly with .bib files and allows one to search, sort, manipulate bibitems in an efficient way. You can download refs from arXiv by providing the numbers or directly copy-paste bibitems from webpages.&lt;br /&gt;
&lt;br /&gt;
More [http://en.wikipedia.org/wiki/Reference_management_software reference management softwares] can be found on the net.&lt;br /&gt;
&lt;br /&gt;
An other possibility, non-open-source, and now own by Elsevier, but still free, is [http://www.mendeley.com/ Mendeley]. It allows to manage the bibliography (.bib files) and in the same time, to manage, annotate and highlight .pdf files. It can get all the metadata of pdf from the doi or arXiv Id quite efficiently.&lt;br /&gt;
&lt;br /&gt;
== Database ==&lt;br /&gt;
&lt;br /&gt;
* [http://arxiv.org/find arXiv]&lt;br /&gt;
* [http://www.adsabs.harvard.edu ADS]&lt;br /&gt;
* [http://scholar.google.fr Scholar Google]&lt;/div&gt;</summary>
		<author><name>Landes</name></author>
	</entry>
</feed>