Michele De Stefano's C++ Utilities
array_iter_usage.pycmd
1 // array_iter_usage.pycmd
2 //
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
4 //
5 // Distributed under the MIT License (See accompanying file LICENSE)
6 
7 
8 /**
9  * \example array_iter_usage.pycmd
10  *
11  * Shows the usage of the array_iter_usage extension from the Python prompt.
12  */
13 
14 mds_utils::python::numpy::NDArrayIterator usage example from the Python prompt:
15 
16 >>> import numpy as np
17 >>> import array_iter_usage as au
18 >>> a = np.array([[1.1,2.2,3.3],[4.4,5.5,6.6]])
19 >>> a
20 array([[ 1.1, 2.2, 3.3],
21  [ 4.4, 5.5, 6.6]])
22 >>> au.print_array_elements(a)
23 
24 Print array:
25 1.1
26 4.4
27 2.2
28 5.5
29 3.3
30 6.6
31 ------------
32 1.1
33 4.4
34 2.2
35 2.2
36 4.4
37 >>> au.modify_array_elements(a)
38 >>> a
39 array([[ 7. , 2.2, 3.3],
40  [ 9. , 5.5, 6.6]])
41 >>> au.print_int_elements(a)
42 
43 Print array:
44 7
45 2
46 3
47 9
48 5
49 6
50 ------------
51 >>> a
52 array([[ 1.1, 2.2, 3.3],
53  [ 4.4, 5.5, 6.6]])
54 >>> au.modify_int_elements(a)
55 >>> a
56 array([[ 10., 11., 3.],
57  [ 9., 5., 6.]])
58 >>> ca = np.array([[1.1,2.2,3.3],[4.4,5.5,6.6]])*(1.+1.j)
59 >>> ca
60 array([[ 1.1+1.1j, 2.2+2.2j, 3.3+3.3j],
61  [ 4.4+4.4j, 5.5+5.5j, 6.6+6.6j]])
62 >>> au.print_fcplx_elements(ca)
63 
64 Print array:
65 (1.1,1.1)
66 (2.2,2.2)
67 (3.3,3.3)
68 (4.4,4.4)
69 (5.5,5.5)
70 (6.6,6.6)
71 ------------
72 >>> au.modify_fcplx_elements(ca)
73 >>> ca
74 array([[ 1.10000002 +1.10000002j, 2.20000005 +2.20000005j,
75  10.10000038+30.10000038j],
76  [ 14.80000019 +9.69999981j, 5.50000000 +5.5j ,
77  6.59999990 +6.5999999j ]])
78