other:python:jyp_steps
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next 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/02/09 16:32] – Added the views side effect 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: | - if you are a Matlab user (but the references are interesting for others as well), you can read the following: | ||
Line 59: | 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 ===== |
other/python/jyp_steps.txt · Last modified: 2025/02/26 11:40 by jypeter