Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i dont find api numpy.c_ #2

Open
ronyuzhang opened this issue Sep 14, 2018 · 3 comments
Open

i dont find api numpy.c_ #2

ronyuzhang opened this issue Sep 14, 2018 · 3 comments

Comments

@ronyuzhang
Copy link

i use c++ and call numpy , but i dont find c++ version of numpy.c_.

@yokaze
Copy link
Owner

yokaze commented Sep 16, 2018

Hi @ronyuzhang, sorry for inconvenience.
Currently pyscience11 does not support numpy.c_ because it is an object rather than being a function. It is difficult to map them into C++ because C++ does not support properties.

Practically it is still possible to use numpy.c_, since pybind11 allows us to access properties via attr function.

#include <pybind11/embed.h>
#include <pybind11/pybind11.h>
#include <pyscience11/numpy.h>

namespace py = pybind11;
namespace n11 = numpy11;

int main(void)
{
    py::scoped_interpreter interpreter;
    py::list li;
    li.append(1);
    li.append(2);
    py::print(py::repr(li));

    auto numpy = n11::import_numpy();
    py::print(py::repr(numpy.attr("c_")[li]));

    return 0;
}

This yields the following result.

$ ./sample
[1, 2]
array([[1],
       [2]])

Does it satisfy your purpose?

@ronyuzhang
Copy link
Author

so great, thanks. It would be better if we could improve the documentation. something, i dont how to use api to achieve my work.

@yokaze
Copy link
Owner

yokaze commented Oct 1, 2018

Thanks for your comment. I will consider to prepare some documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants