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/22 18:07] – More changes jypeter | other:python:jyp_steps [2016/02/18 12:02] – Started the debug section jypeter | ||
---|---|---|---|
Line 49: | Line 49: | ||
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: | ||
+ | - [[https:// | ||
+ | - [[http:// | ||
- read the [[https:// | - read the [[https:// | ||
- have a quick look at the full documentation to know where things are | - have a quick look at the full documentation to know where things are | ||
Line 56: | Line 60: | ||
- 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 128: | Line 189: | ||
* [[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 ==== | ||
+ | |||
+ | ==== Using pydebug ==== | ||
+ | |||
===== Improving the performance of your code ===== | ===== Improving the performance of your code ===== | ||
Line 135: | Line 205: | ||
* **make sure that your script is not using too much memory** (the amount depends on the computer you are using)! Your script should be scalable (e.g. keeps on working even when your data gets bigger), so it's a good idea to load only the data you need in memory (e.g. not all the time steps), and learn how to load chunks of data | * **make sure that your script is not using too much memory** (the amount depends on the computer you are using)! Your script should be scalable (e.g. keeps on working even when your data gets bigger), so it's a good idea to load only the data you need in memory (e.g. not all the time steps), and learn how to load chunks of data | ||
- | * **make sure that you are using array/ | + | * **make sure that you are using array/ |
If your script is still not fast enough, there is a lot you can do to improve it, without resorting to parallelization (that may introduce extra bugs rather that extra performance). See the sections below | If your script is still not fast enough, there is a lot you can do to improve it, without resorting to parallelization (that may introduce extra bugs rather that extra performance). See the sections below |
other/python/jyp_steps.txt · Last modified: 2025/02/26 11:40 by jypeter