mirror of
https://github.com/boostorg/python.git
synced 2026-01-23 05:42:30 +00:00
boost.python.numpy - added ndarray::reshape
This commit is contained in:
@@ -115,6 +115,9 @@ public:
|
||||
/// @brief Eliminate any unit-sized dimensions.
|
||||
ndarray squeeze() const;
|
||||
|
||||
/// @brief Equivalent to self.reshape(*shape) in Python.
|
||||
ndarray reshape(tuple const & shape) const;
|
||||
|
||||
/**
|
||||
* @brief If the array contains only a single element, return it as an array scalar; otherwise return
|
||||
* the array.
|
||||
|
||||
@@ -185,6 +185,14 @@ ndarray ndarray::squeeze() const {
|
||||
);
|
||||
}
|
||||
|
||||
ndarray ndarray::reshape(tuple const & shape) const {
|
||||
return ndarray(
|
||||
python::detail::new_reference(
|
||||
PyArray_Reshape(reinterpret_cast<PyArrayObject*>(this->ptr()), shape.ptr())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
object ndarray::scalarize() const {
|
||||
Py_INCREF(ptr());
|
||||
return object(python::detail::new_reference(PyArray_Return(reinterpret_cast<PyArrayObject*>(ptr()))));
|
||||
|
||||
Reference in New Issue
Block a user