Skip to content

convert a vector<float> to ndarray does not work correctly #142

Closed
@bpkcl630

Description

@bpkcl630

Hi,

I have a trouble when using boost 1.64.0 to convert a vector to a 2D ndarray.

I try to use code like this

np::ndarray pyArray = np::from_data(vec.data(), np::dtype::get_builtin<float>(), np::tuple(rows, cols), py::make_tuple(cols, 1), py::object() );

when I return it to python the result is not same as C++. Then I change this to another way which is

np::ndarray result = np::zeros(np::tuple(rows, cols), np::dtype::get_builtin<float>());
std::copy(vec.begin(), vec.end(), reinterpret_cast<float*>(result.get_data()));

and it is works correctly now.

I am not sure it is a bug or I use the from_data() in a wrong way.

Thanks a lot for your help!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions