User Tools

Site Tools


other:python:misc_by_jyp

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
other:python:misc_by_jyp [2023/12/08 15:36]
jypeter Added the efficient looping section
other:python:misc_by_jyp [2024/04/19 12:02] (current)
jypeter [Data representation] Corrected link to an old JYP tutorial
Line 5: Line 5:
 </​WRAP>​ </​WRAP>​
  
 +===== Extra tutorials =====
  
 +Only **when you have already read all the content of this page several times**, and you are looking for new ideas
 +
 +  * [[https://​medium.com/​@yaduvanshineelam09/​ultimate-python-cheat-sheet-practical-python-for-everyday-tasks-8a33abc0892f|Ultimate Python Cheat Sheet: Practical Python For Everyday Tasks]]
 ===== Reading/​setting environments variables ===== ===== Reading/​setting environments variables =====
  
Line 314: Line 318:
  
  
-===== Efficient looping with numpy, map and itertools =====+===== Efficient looping with numpy, mapitertools ​and list comprehension ​=====
  
-<wrap hi>Big, nested, explicit loops should be avoided at all cost</​wrap>,​ in order to reduce a script execution time!+<wrap hi>Big, nested, explicit ​''​for'' ​loops should be avoided at all cost</​wrap>,​ in order to reduce a script execution time!
  
   * **''​numpy''​ arrays** should be used when dealing with //numerical data//   * **''​numpy''​ arrays** should be used when dealing with //numerical data//
Line 358: Line 362:
 ... ...
 A0$, A0!, A1$, A1!, B0$, B0!, B1$, B1!,</​code>​ A0$, A0!, A1$, A1!, B0$, B0!, B1$, B1!,</​code>​
 +
 +  * The [[https://​docs.python.org/​3/​tutorial/​datastructures.html?​highlight=comprehension#​list-comprehensions|list comprehension]] (aka //implicit loops//) can also be used to generate lists from lists
 +    * Example: converting a list of integers to a list of strings\\ Note: in that case, you should rather use the ''​map''​ function detailed above
 +      * <​code>>>>​ my_ints = [1, 2, 3]
 +
 +>>>​ [ str(ii) for ii in my_ints ]
 +['​1',​ '​2',​ '​3'​]</​code>​
 ===== numpy related stuff ===== ===== numpy related stuff =====
  
Line 537: Line 548:
 A few notes for a future section or page about about //data representation//​ (bits and bytes) on disk and in memory, vs //data format// A few notes for a future section or page about about //data representation//​ (bits and bytes) on disk and in memory, vs //data format//
  
-FIXME Add parts (pages 28 to 37) of this [[https://wiki.lsce.ipsl.fr/​pmip3/doku.php/other:​python:​jyp_steps#​part_2|old tutorial]] to this section+FIXME Add parts (pages 28 to 37) of this [[http://www.lsce.ipsl.fr/​Phocea/file.php?​class=page&​file=5/pythonCDAT_jyp_2sur2_070306.pdf|old tutorial]] to this section
  
 ==== Base notions ==== ==== Base notions ====
other/python/misc_by_jyp.1702049788.txt.gz · Last modified: 2023/12/08 15:36 by jypeter