2
0
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:
Jim Bosch
2010-06-29 07:55:33 +00:00
parent f3aecdf2f4
commit c7db44f617
2 changed files with 11 additions and 0 deletions

View File

@@ -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.

View File

@@ -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()))));