admin 管理员组文章数量: 887021
2024年2月19日发(作者:染膏颜色代码记忆口诀1到8)
}void hello::on_btnTest_clicked(){ test1(); test2();}void test2(){ if (!Py_isInitialize()) return; import_array() PyRun_simpleString("import sys"); QString setSysPath = QString("('%1')").arg(QCoreApplication::applicationDirPath()); PyRun_SimpleString(tring().c_str()); PyObject* pModule = PyImport_ImportModule("test2"); if (!pModule) { qDebug("Can not open python file!"); return;
} PyObject * pFunc = PyObject_GetAttrString(pModule, "test2Function"); if (!pFunc) { qDebug("Get Function failed!"); return; }
PyObject* listUP = PyList_New(3); double arrUP[] = {1.1,2,3}; for (int i = 0; i < 3; i++) { PyList_SetItem(listUP, i, Py_BuildValue("d", arrUP[i])); }
PyObject* listLISAN1 = PyList_New(5); for (int i = 0; i < 5; i++) { PyList_SetItem(listLISAN1, i, Py_BuildValue("i", i+1); } PyObject* listLISAN2 = PyList_New(7); for (int i = 0; i < 7; i++) { PyList_SetItem(listLISAN2, i, Py_BuildValue("i", i+1); } PyObject* listLISAN = PyList_New(0); PyList_Append(listLISAN, listLISAN1); PyList_Append(listLISAN, listLISAN2);
PyObject* DOWNEST = PyFloat_FromDouble(-1.0e+100);
PyObject* args = PyTuple_New(3); PyTuple_SetItem(args, 0, listUP); PyTuple_SetItem(args, 1, listLISAN); PyTuple_SetItem(args, 2, DOWNEST);
PyObject* res = PyEval_CallObject(pFunc, args);
PyObject* poMinMubiaos = PyTuple_GetItem(res, 0); PyObject* poFanggans = PyTuple_GetItem(res, 1); PyObject* poMubiaos = PyTuple_GetItem(res, 2);
{ qDebug("MinMubiaos = %frn", PyFloat_AsDouble(poMinMubiaos)); } {
{ //cout << "poFanggans type: " << poFanggans->ob_type->tp_name << endl << flush; // type: list cout << "Fangans=[rn" << flush; for (int i = 0; i < PyList_Size(poFanggans); i++) { PyObject* childList = PyList_GetItem(poFanggans, i); cout << "[" << flush; for (int j = 0; j < PyList_Size(childList): j++) { if (j != 0) cout << ", " << flush; cout << PyFloat_AsDouble(PyList_GetItem(childList, j)) << flush; } cout << "], rn" << flush; } cout << "] rn" << flush; } { cout << "poMinMubiaos size = " << PyArray_Size(poMinMubiaos) << endl; PyArrayObject* pyArr = reinterpret_cast
} PyObject * pFunc = PyObject_GetAttrString(pModule, "test1Function"); if (!pFunc) { qDebug("Get Function failed!"); return; }// data: [[1 2 3], [1 2 3]] const int SIZE1 = 2; const int SIZE2 = 3; const int ND = 2; npy_intp dims[ND] = {SIZE1, SIZE2}; double (*c_arr)[SIZE2] = new double[SIZE1][SIZE2]; for (int i = 0; i < SIZE1; i++) for (int j = 0; j < SIZE2; j++) c_arr[i][j] = i*SIZE1+j;
pyArrayObject *pyArr; pyArr = reinterpret_cast
版权声明:本文标题:qt传递二维数组,列表给python 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1708327406h519900.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论