Convert vector of string to numpy array
Open
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
Description
If the max length of string is known in advance, I can write code like:
std::vector<std::string> v = {"1", "23", "456"};
using S8 = char[8];
py::array_t<S8> arr(v.size());
auto pdest = static_cast<S8*>(arr.request().ptr);
for (std::size_t i = 0; i < v.size(); ++i) {
std::strncpy(pdest[i], v[i].data(), 8);
}
But what if the vector is created dynamically and the longest string is unknown? Please advise.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No repository file or test is named. Start by reviewing the C++ example and the pybind11 NumPy-array conversion entry points for std::vectorstd::string; determine the supported behavior for dynamically sized strings, then add coverage that demonstrates the resulting conversion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, numpy, python
- Domain
- api, data
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100