Create a view of an array in a different data type. This function may fundamentally reinterpret the data in the array. It is the responsibility of the caller to ensure that this is safe. Only supports the `dtype` argument, the `type` argument is omitted, to be added as needed.
| 1305 | /// Only supports the `dtype` argument, the `type` argument is omitted, |
| 1306 | /// to be added as needed. |
| 1307 | array view(const std::string &dtype) { |
| 1308 | auto &api = detail::npy_api::get(); |
| 1309 | auto new_view = reinterpret_steal<array>(api.PyArray_View_( |
| 1310 | m_ptr, dtype::from_args(pybind11::str(dtype)).release().ptr(), nullptr)); |
| 1311 | if (!new_view) { |
| 1312 | throw error_already_set(); |
| 1313 | } |
| 1314 | return new_view; |
| 1315 | } |
| 1316 | |
| 1317 | /// Ensure that the argument is a NumPy array |
| 1318 | /// In case of an error, nullptr is returned and the Python error is cleared. |