other:python:jyp_steps
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
other:python:jyp_steps [2016/01/29 16:41] – Added the numpy for matlab users references jypeter | other:python:jyp_steps [2016/05/20 15:41] – Added a link to 'Working with Python' at the top jypeter | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== JYP's recommended steps for learning python ====== | ====== JYP's recommended steps for learning python ====== | ||
+ | |||
+ | <note tip>If you don't know which python distribution to use and how to start the python interpreter, | ||
As can be expected, there is **a lot** of online python documentation available, and it's easy to get lost. You can always use google to find an answer to your problem, and you will probably end up looking at lots of answers on [[http:// | As can be expected, there is **a lot** of online python documentation available, and it's easy to get lost. You can always use google to find an answer to your problem, and you will probably end up looking at lots of answers on [[http:// | ||
Line 49: | Line 51: | ||
Where: [[http:// | Where: [[http:// | ||
- | How to get started? | + | ==== Getting |
- always remember that indices start at '' | - always remember that indices start at '' | ||
- if you are a Matlab user (but the references are interesting for others as well), you can read the following: | - if you are a Matlab user (but the references are interesting for others as well), you can read the following: | ||
Line 59: | Line 62: | ||
- Numpy Reference Guide | - Numpy Reference Guide | ||
- Scipy Reference Guide | - Scipy Reference Guide | ||
+ | |||
+ | ==== Beware of the array view side effects ==== | ||
+ | |||
+ | <note warning> | ||
+ | |||
+ | That is not a problem when you only read the values, but **if you change the values of the //View//, you change the values of the first array** (and vice-versa)! If that is not what want, do not forget to **make a copy** of the data before working on it! | ||
+ | |||
+ | //Views// are a good thing most of the time, so only make a copy of your data when needed, because otherwise copying a big array will just be a waste of CPU and computer memory. Anyway, it is always better to understand what you are doing... :-P | ||
+ | |||
+ | Check the example below and the [[https:// | ||
+ | |||
+ | <code python> | ||
+ | >>> | ||
+ | >>> | ||
+ | >>> | ||
+ | array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
+ | [10, 11, 12, 13, 14, 15, 16, 17, 18, 19], | ||
+ | [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]]) | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | array([10, 11, 12, 13, 14, 15, 16, 17, 18, 19]) | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | array([10, 11, 12, 0, 0, 0, 0, 17, 18, 19]) | ||
+ | |||
+ | >>> | ||
+ | array([[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9], | ||
+ | [10, 11, 12, 0, 0, 0, 0, 17, 18, 19], | ||
+ | [20, 21, 22, 23, 24, 25, 26, 27, 28, 29]]) | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | array([[ 0, 1, -1, -1, 4, 5, 6, 7, 8, 9], | ||
+ | [10, 11, -1, -1, 0, 0, 0, 17, 18, 19], | ||
+ | [20, 21, -1, -1, 24, 25, 26, 27, 28, 29]]) | ||
+ | |||
+ | >>> | ||
+ | array([10, 11, -1, -1, 0, 0, 0, 17, 18, 19]) | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | array([10, 11, -1, -1, 0, 0, 0, 17, 18, 19]) | ||
+ | |||
+ | >>> | ||
+ | >>> | ||
+ | array([9, 9, 9, 9, 9, 9, 9, 9, 9, 9]) | ||
+ | |||
+ | >>> | ||
+ | array([10, 11, -1, -1, 0, 0, 0, 17, 18, 19]) | ||
+ | |||
+ | >>> | ||
+ | array([[ 0, 1, -1, -1, 4, 5, 6, 7, 8, 9], | ||
+ | [10, 11, -1, -1, 0, 0, 0, 17, 18, 19], | ||
+ | [20, 21, -1, -1, 24, 25, 26, 27, 28, 29]]) | ||
+ | </ | ||
===== cdms2 and netCDF4 ===== | ===== cdms2 and netCDF4 ===== | ||
Line 131: | Line 191: | ||
* [[http:// | * [[http:// | ||
+ | |||
+ | ===== Debugging your code ===== | ||
+ | |||
+ | There is only so much you can do with staring at your code in your favorite text editor, and adding '' | ||
+ | |||
+ | ==== Debugging in text mode ==== | ||
+ | |||
+ | - Start the script with: '' | ||
+ | - Type '' | ||
+ | - Type '' | ||
+ | - Use '' | ||
+ | - Type '' | ||
+ | - Use '' | ||
+ | - Type '' | ||
+ | - Use '' | ||
+ | * '' | ||
+ | * '' | ||
+ | - Check the [[https:// | ||
+ | |||
+ | ==== Using pydebug ==== | ||
+ | |||
+ | Depending on the distribution, | ||
===== Improving the performance of your code ===== | ===== Improving the performance of your code ===== | ||
Line 143: | Line 225: | ||
Hint: before optimizing your script, you should spent some time // | Hint: before optimizing your script, you should spent some time // | ||
+ | |||
+ | ==== Useful packages ==== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[http:// | ||
==== Tutorials by Ian Osvald ==== | ==== Tutorials by Ian Osvald ==== |
other/python/jyp_steps.txt · Last modified: 2025/02/26 11:40 by jypeter