From c7db44f617f7e508219f7efc9ee49036cdd673b2 Mon Sep 17 00:00:00 2001 From: Jim Bosch Date: Tue, 29 Jun 2010 07:55:33 +0000 Subject: [PATCH] boost.python.numpy - added ndarray::reshape --- boost/python/numpy/ndarray.hpp | 3 +++ libs/python/numpy/src/ndarray.cpp | 8 ++++++++ 2 files changed, 11 insertions(+) diff --git a/boost/python/numpy/ndarray.hpp b/boost/python/numpy/ndarray.hpp index 170112c3..6ca0f499 100644 --- a/boost/python/numpy/ndarray.hpp +++ b/boost/python/numpy/ndarray.hpp @@ -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. diff --git a/libs/python/numpy/src/ndarray.cpp b/libs/python/numpy/src/ndarray.cpp index 30820f4b..1d7641fd 100644 --- a/libs/python/numpy/src/ndarray.cpp +++ b/libs/python/numpy/src/ndarray.cpp @@ -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(this->ptr()), shape.ptr()) + ) + ); +} + object ndarray::scalarize() const { Py_INCREF(ptr()); return object(python::detail::new_reference(PyArray_Return(reinterpret_cast(ptr()))));