1 // numpy_array_usage.pycmd
3 // Copyright (c) 2014 - Michele De Stefano (micdestefano@users.sourceforge.net)
5 // Distributed under the MIT License (See accompanying file LICENSE)
9 * \example numpy_array_usage.pycmd
11 * Shows the usage of the numpy_array_usage extension from the Python prompt.
14 numpy_array.hpp functionalities usage example from the Python prompt:
16 >>> import numpy_array_usage as nau
17 >>> v = nau.create_NumPy1DArray()
19 <Swig Object of type 'boost::numeric::ublas::NumPy1DArray< double > *' at 0x7f168afcb840>
20 >>> v2 = nau.create_npy_array()
22 <type 'numpy.ndarray'>
24 array([ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6])
25 >>> nau.get_vec_no_conversion(v)
27 [6](1.1,2.2,3.3,4.4,5.5,6.6)
28 >>> nau.destroy_NumPy1DArray(v)
30 >>> cv = nau.create_npy_array_cplx()
32 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])
44 >>> sv = nau.create_npy_array_short()
46 array([-1, 2, -3, 4, 5, -6], dtype=int16)
49 [6](1.1,2.2,3.3,4.4,5.5,6.6)
51 vector_usage.py:107: ComplexWarning: Casting complex values to real discards the imaginary part
52 return _vector_usage.get_vec(*args)
54 [6](1.1,2.2,3.3,4.4,5.5,6.6)
56 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])
57 >>> nau.get_vec_cplx(cv)
59 [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))
60 >>> nau.get_vec_fcplx(cv)
62 [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))
63 >>> nau.get_vec_cast(cv)
64 vector_usage.py:147: ComplexWarning: Casting complex values to real discards the imaginary part
65 return _vector_usage.get_vec_cast(*args)
68 >>> nau.get_vec_cast(v2)
71 >>> import numpy as np
72 >>> v = np.array([ 1.1, 2.2, 3.3, 4.4, 5.5, 6.6],dtype=np.complex64)*(1.1+1.1j)
74 array([ 1.21000004+1.21000004j, 2.42000008+2.42000008j,
75 3.63000011+3.63000011j, 4.84000015+4.84000015j,
76 6.05000019+6.05000019j, 7.26000023+7.26000023j], dtype=complex64)
77 >>> nau.get_vec_fcplx(v)
79 [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))
81 >>> v = np.array([1.1,2.2,3.3])
83 array([ 1.1, 2.2, 3.3])
87 array([ 2.2, 4.4, 6.6])
91 array([ 4.4, 8.8, 13.2])