c++ - Doing permutation of the dimension in a Boost multi_array -
this question has answer here:
i'm writing c++ program using boost multi_array library. have 4-dimensional array with, example, shape of [5][10][100][20]. , change shape of array [100][10][5][20]. proper way this?
thank you
assuming ask reshaping , not permutation of dimensions (those operations not same), can use reshape member function of boost::multi_array, (example taken verbatim boost multi-array documentation)
typedef boost::multi_array<double, 3> array_type; array_type::extent_gen extents; array_type a(extents[2][3][4]); boost::array<array_type::index, 3> dims = {{4, 3, 2}}; a.reshape(dims); full example below:
#include <iostream> #include <boost/multi_array.hpp> int main() { using array_type = boost::multi_array<double, 2>; array_type::extent_gen extents; array_type a(extents[1][2]); // 1 x 2 array a[0][0] = 1; a[0][1] = 2; std::cout << a[0][0] << ' ' << a[0][1] << '\n'; boost::array<array_type::index, 2> dims = {{2,1}}; a.reshape(dims); // reshape 2 x 1 std::cout << a[0][0] << ' ' << a[1][0] << '\n'; // verify } as dimension permutation, far know boost::multi_array not have function that, you'd need write own.
Comments
Post a Comment