Git Product home page Git Product logo

Comments (1)

wolfv avatar wolfv commented on May 18, 2024

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<size_t>. Currently we only have a constructor from the std::vector shape type.
If you use the from_shape overload it should be fine.


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());

from xtensor-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.