Closed iamthebot closed 6 years ago
Hi @iamthebot
this is actually a corner-case with the initializer lists that we have. Initialization from initializer list is used to create the array, e.g. xt::pyarray<double> a({{1,2,3}, {4,5,6}});
will create a pyarray with shape {2, 3} and the values inside.
To easily use initializer lists for the shape to create xarrays etc, we have added the named constructor as follows: auto a = xt::pyarray<double>::from_shape({3, 3});
which returns the array with correct shape.
As the syntax is a little verbose, we have also added the xt::empty({3,3});
function which will come in xtensor 0.16 (however, in this case it would actually return a xtensor, as it can infer that {3, 3} has 2 dimensions at compile time.
You can also force the shape-overload by constructing a shape type in the constructor call pyarray<double> a(std::vector<std::size_t>{1,2,3,4});
should work.
And your last error ... we actually have "two" shape types in xtensor python: one "inner" which wraps the numpy shape, and one "outer" which is the std::vector
It looks like we haven't added the from_shape static constructors to pyarray / pytensor yet! Sorry about that!! I'm filing a bug for that, it should land in the next release for sure! So the current workaround is probably
xt::pyarray<double> a; a.reshape(b.shape());
Looks like #120 still isn't fixed as of latest xtensor-python master (w/ xtensor 0.15.9).
Taking the result of
xt::pyarray<float>.shape()
and callingreshape(<that value>)
on another array produces the following errorI'm using GCC7.
Similarly, instantiating a new pyarray using the shape of another array fails with the following error: