You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

pybind11中使用std::distance处理py::array_t变量时的异常问题咨询

pybind11中使用std::distance处理py::array_t变量时的异常问题咨询

大家好,我最近在pybind11开发中碰到了一个奇怪的问题,想请教下各位大佬:

我想要获取py::array_t类型变量中最小元素的索引,于是尝试用std::distance配合std::min_element来实现,但是运行下面这段代码时程序直接卡住了:

std::distance(arr.begin(), std::min_element(arr.begin(), arr.end()))

一开始我以为是py::array_t的迭代器和std::distance不兼容,但我做了个简单测试,单独运行下面这段代码却完全正常:

std::distance(arr.begin(), arr.end())

实在想不通为什么第一种组合使用的方式会出问题,有没有人能帮忙解释下原因呀?非常感谢!

备注:内容来源于stack exchange,提问作者ulti_ww

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.14 12:37:59