Comments (1)
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)
- Enable load cast `xt::xtensor<...>`
- Error with strided view
- is:issue how to sum string type load from csv? and how to convert string column to timestamp? HOT 1
- The URL listed on the project's page is a broken link HOT 1
- Doesn't install the python binding HOT 4
- Tests fail to find Python.h HOT 6
- Segmentation fault of MSVC 19
- Broadcasting problem on basic operations? HOT 5
- Retrieving xt::pyarray when embedding python using pybind11 HOT 1
- Add support for nanobind? HOT 5
- Support for custom types? HOT 1
- problem calculating quantile on pytensor HOT 7
- Assignment of Expression to Tensor of Incorrect Dimensions - Strange Error - Numpy Unable to Allocate very Large Array HOT 4
- Build C++ XTensor project as Python package so users can `pip install` without any additional dependencies
- How to convert xt::pyarray to xt::xarray? HOT 1
- /home/mona/anaconda3/envs/zephyr/include/xtensor-python/pycontainer.hpp:30:10: fatal error: numpy/arrayobject.h: No such file or directory HOT 2
- Fix Windows CI
- xtensor cmake variables do not match variables in CMakeLists.txt
- Restore #296 when all python versions support it on conda-forge
- support numpy>2.0?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from xtensor-python.