简体   繁体   English

numpy C-API:C中的标量乘法

[英]numpy C-API: scalar multiplication in C

How can I perform an element-wise multiplication of a numpy-nd-array with an arbitrary double-scalar in C? 如何在C中使用任意双标量执行numpy-nd-array的元素乘法?

I'm searching for a api-function like this: 我正在寻找这样的api函数:

// C-code
PyArray_MultiplyWithScalar((PyArrayObject *) myarray, double scalar_value);

corresponding to pure numpy: 对应纯粹的numpy:

# pure python
myarray = myarray * scalar_value

My current (bad) solution is to iterate over all entries and perform the normalization manually. 我当前(坏)的解决方案是迭代所有条目并手动执行规范化。

I don't know the right answer to your question, but if you do a loop in C that should be as fast as it gets, I would even think faster than calling a python api function if you do it right. 我不知道你的问题的正确答案,但如果你在C中做一个应该尽可能快的循环,我甚至会比调用python api函数更快,如果你做得对。 Doing it that way you can even edit the array in place without the need for additional memory. 这样做你甚至可以在不需要额外内存的情况下编辑阵列。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM