1 // ublas_pkg_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 ublas_pkg_usage.pycmd
11 * Shows the usage of the ublas_pkg_usage extension from the Python prompt.
12 * Furthermore, it shows how to reuse classes wrapped by the
13 * mds_utils.ublas.ublas.py module.
15 * Before using the ublas_pkg_usage module, ensure that your
16 * PYTHONPATH environment variable contains the path to reach the
17 * mds_utils Python package. For example, if the mds_utils package has
18 * been built but not installed yet, it is typically found into the
19 * mds-utils/python/build/lib.linux-<arch>-<Python version> directory
20 * (for a Linux build) and you have to add this path to your PYTHONPATH
21 * variable. After that, you can import the ublas_pkg_usage module and
25 >>> import ublas_pkg_usage as ubpu
26 >>> v = ubpu.create_vector()
28 <mds_utils.ublas.ublas.vector_d; proxy of <Swig Object of type 'boost::numeric::ublas::vector< double > *' at 0x7f9257478ea0> >
32 <bound method vector_d.__str__ of <mds_utils.ublas.ublas.vector_d; proxy of <Swig Object of type 'boost::numeric::ublas::vector< double > *' at 0x7f9257478ea0> >>
36 array([ 1.1, 2.2, 3.3])
39 >>> M = ubpu.create_compressed_matrix()
41 <mds_utils.ublas.ublas.compressed_matrix_drow; proxy of <Swig Object of type 'boost::numeric::ublas::compressed_matrix< double,boost::numeric::ublas::row_major > *' at 0x22171e0> >
43 [4,3]((0,0,2.2),(1.1,0,0),(0,0,0),(0,3.3,0))
44 >>> sp_M = M.to_sparse_mtx()
46 <4x3 sparse matrix of type '<type 'numpy.float64'>'
47 with 3 stored elements in Compressed Sparse Row format>
49 matrix([[ 0. , 0. , 2.2],
54 array([[ 0. , 0. , 2.2],
58 >>> v1 = ubpu.my_vec()
59 >>> import numpy as np
60 >>> v1.from_array(np.array([11.1,22.2,33.3]))