编写我自己的 ufunc;输入类型不支持 ufunc

问题描述

我正在尝试编写一个将 numpy 字符串数组转换为浮点数组的 C 函数。如何在 C 中接收 numpy 的数组作为 const char *?


static void double_logitprod(char **args,npy_intp *dimensions,npy_intP* steps,void* data)
{
    npy_intp i;
    npy_intp n = dimensions[0];
    char *in1 = args[0],*in2 = args[1];
    char *out = args[2];
    npy_intp in1_step = steps[0]; 
    npy_intp out_step = steps[2];

    for (i = 0; i < n; i++) {
        /*BEGIN main ufunc computation*/
        char *tmp1 = *((char **) in1);
        double tmp2 = *((double *)in2);
        *((double *) out) = to_float(tmp1,tmp2);
        /*END main ufunc computation*/

        in1 += in1_step;
        out += out_step;
    }
}


/*This a pointer to the above function*/
PyUFuncGenericFunction funcs[1] = {&double_logitprod};

/* These are the input and return dtypes of logit.*/

static char types[3] = {NPY_STRING,NPY_DOUBLE,NPY_DOUBLE};

如何在 C 中接受一个 numpy 字符串数组? NPY_STRING 或 NPY_UNICODE 给出错误

Numpy 字符串数组是这样的:

x = np.array(['1.0','2.0','N/A'])

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)