pyscience11
pyscience11 copied to clipboard
i dont find api numpy.c_
i use c++ and call numpy , but i dont find c++ version of numpy.c_.
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?
so great, thanks. It would be better if we could improve the documentation. something, i dont how to use api to achieve my work.
Thanks for your comment. I will consider to prepare some documentation.