This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | Next revision Both sides next revision | ||
other:python:misc_by_jyp [2022/05/23 15:36] jypeter [numpy related stuff] Added the "variable number of indices" section |
other:python:misc_by_jyp [2022/05/23 16:01] jypeter [numpy related stuff] Changed the VIEW update warnng example |
||
---|---|---|---|
Line 291: | Line 291: | ||
(4, 10) | (4, 10) | ||
- | >>> # WARNING! WARNING! A slice is a VIEW and NOT A COPY | + | >>> # WARNING! DANGERRRR! NEVER forget that a VIEW is NOT A COPY |
- | >>> i10[my_fancy_slices] = -1 | + | >>> # and that you can change the content of the original array by mistake |
+ | >>> my_view = i10[my_slices] | ||
+ | >>> my_view[:, :] = -1 | ||
+ | >>> my_view | ||
+ | array([[-1., -1.], | ||
+ | [-1., -1.], | ||
+ | [-1., -1.], | ||
+ | [-1., -1.]]) | ||
>>> i10 | >>> i10 | ||
array([[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], | array([[ 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.], | ||
[ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], | [ 0., 1., 0., 0., 0., 0., 0., 0., 0., 0.], | ||
[ 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], | [ 0., 0., 1., 0., 0., 0., 0., 0., 0., 0.], | ||
- | [-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.], | + | [ 0., 0., 0., 1., -1., -1., 0., 0., 0., 0.], |
- | [-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.], | + | [ 0., 0., 0., 0., -1., -1., 0., 0., 0., 0.], |
- | [-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.], | + | [ 0., 0., 0., 0., -1., -1., 0., 0., 0., 0.], |
- | [-1., -1., -1., -1., -1., -1., -1., -1., -1., -1.], | + | [ 0., 0., 0., 0., -1., -1., 1., 0., 0., 0.], |
[ 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.], | [ 0., 0., 0., 0., 0., 0., 0., 1., 0., 0.], | ||
[ 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], | [ 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.], | ||
- | [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]]) | + | [ 0., 0., 0., 0., 0., 0., 0., 0., 0., 1.]])</code> |
- | </code> | + | |
=== Finding and counting unique values === | === Finding and counting unique values === |