|
1 | | -# python-multi-array |
2 | | -A python wrapper for boost::multi_array |
3 | | - |
4 | | -# Install |
5 | | - |
| 1 | +# Overview |
| 2 | +python-multi-array exports ```std::shared_ptr<boost::multi_array<T, N>>``` for |
6 | 3 | ```
|
7 | | -$ make |
| 4 | +T: bool, uint8, uint16, uint32, uint64, int8, int16, int32, int64, float32 and floa64 |
| 5 | +N: 1 to 8. |
8 | 6 | ```
|
9 | 7 |
|
10 | | -You may change the include directory by editing setup.py. |
| 8 | +The library serves a powerful tool to cooperate python and its extension modules written in C++. |
| 9 | +You can create arrays and set values in python, make heavy calculation in C++ (OpenMP and every other C++ tools are available,) and get back to python and display the results using matplotlib. |
11 | 10 |
|
12 | | -# Usage |
| 11 | +The array is allocated via multi_array.make. |
| 12 | +```python |
| 13 | +>>> import numpy, multi_array |
| 14 | +>>> multi_array.make((4, 2), numpy.float32) |
| 15 | +<multi_array.shared_float_matrix object at 0x10aeb3f50>) |
| 16 | +``` |
| 17 | + |
| 18 | +The array itself has simple I/O APIs: |
| 19 | +```python |
| 20 | +>>> x = multi_array.make((4, 2), numpy.float32) |
| 21 | +>>> x.num_dimensions() |
| 22 | +2 |
| 23 | +>>> x.num_elements() |
| 24 | +8 |
| 25 | +>>> x.shape() |
| 26 | +(4, 2) |
| 27 | +>>> x[1, 1] = 3 |
| 28 | +>>> x[1, 1] |
| 29 | +3.0 |
| 30 | +``` |
13 | 31 |
|
| 32 | +and conversion APIs with numpy.ndarray. |
14 | 33 | ```python
|
15 | | ->>> import multi_array, scipy |
16 | | ->>> x = multi_array.make((2, 4), multi_array.float32) |
17 | | ->>> x.set(scipy.rand(2, 4)) |
| 34 | +>>> x.set(scipy.rand(4, 2)) |
| 35 | +>>> type(x.get()) |
| 36 | +<type'numpy.ndarray'> |
18 | 37 | >>> x.get()
|
19 | | -array([[ 0.9504686 , 0.37968314, 0.93876582, 0.17501496], |
20 | | - [ 0.87398338, 0.83764452, 0.69423091, 0.29122856]], dtype=float32) |
21 | | ->>> x[1, 2] |
22 | | -0.6942309141159058 |
| 38 | +array([[ 0.91382688, 0.374331 ], |
| 39 | + [ 0.43389955, 0.5571261 ], |
| 40 | + [ 0.6937117 , 0.40599877], |
| 41 | + [ 0.80906659, 0.75029951]], dtype=float32) |
| 42 | +``` |
| 43 | + |
| 44 | +# Install |
| 45 | + |
23 | 46 | ```
|
| 47 | +$ make |
| 48 | +``` |
| 49 | + |
| 50 | +You may change the include directory by editing setup.py. |
0 commit comments