3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
5 // Distributed under the MIT License (See accompanying file LICENSE)
9 * \example vector_usage.pycmd
11 * Shows the usage of the vector_usage extension from the Python prompt.
14 vector.hpp functionalities usage example from the Python prompt:
16 >>> import vector_usage as vu
17 >>> v = vu.create_npy_array()
19 array([ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6])
29 >>> v2 = vu.create_ublas_vector()
33 <Swig Object of type 'boost::numeric::ublas::vector< double > *' at 0x7f44f0225ed0>
34 >>> vu.get_vec_no_conversion(v2)
36 [6](1.1,2.2,3.3,4.4,5.5,6.6)
37 >>> vu.destroy_ublas_vector(v2)
38 >>> cv = vu.create_npy_array_cplx()
40 array([ 1.1+1.1j, 2.2+2.2j, 3.3+3.3j, 4.4+4.4j, 5.5+5.5j, 6.6+6.6j])
52 >>> sv = vu.create_npy_array_short()
54 array([-1, 2, -3, 4, 5, -6], dtype=int16)
57 [6](1.1,2.2,3.3,4.4,5.5,6.6)
59 vector_usage.py:107: ComplexWarning: Casting complex values to real discards the imaginary part
60 return _vector_usage.get_vec(*args)
62 [6](1.1,2.2,3.3,4.4,5.5,6.6)
64 array([ 1.1+1.1j, 2.2+2.2j, 3.3+3.3j, 4.4+4.4j, 5.5+5.5j, 6.6+6.6j])
65 >>> vu.get_vec_cplx(cv)
67 [6]((1.1,1.1),(2.2,2.2),(3.3,3.3),(4.4,4.4),(5.5,5.5),(6.6,6.6))
68 >>> vu.get_vec_fcplx(v)
70 [6]((1.1,0),(2.2,0),(3.3,0),(4.4,0),(5.5,0),(6.6,0))
72 array([ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6])
73 >>> vu.get_vec_cast(cv)
74 vector_usage.py:147: ComplexWarning: Casting complex values to real discards the imaginary part
75 return _vector_usage.get_vec_cast(*args)
78 >>> vu.get_vec_cast(v)
81 >>> import numpy as np
82 >>> v = np.array([ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6],dtype=np.complex64)*(1.1+1.1j)
84 array([ 1.21000004+1.21000004j, 2.42000008+2.42000008j,
85 3.63000011+3.63000011j, 4.84000015+4.84000015j,
86 6.05000019+6.05000019j, 7.26000023+7.26000023j], dtype=complex64)
87 >>> vu.get_vec_fcplx(v)
89 [6]((1.21,1.21),(2.42,2.42),(3.63,3.63),(4.84,4.84),(6.05,6.05),(7.26,7.26))