Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 C 中执行 numpy-nd-array 与任意双标量的元素乘法?
我正在寻找这样的 api 函数:
// C-code PyArray_MultiplyWithScalar((PyArrayObject *) myarray, double scalar_value);
对应于纯numpy:
# pure python myarray = myarray * scalar_value
我当前的(坏的)解决方案是遍历所有条目并手动执行规范化。
我不知道你的问题的正确答案,但是如果你在 C 中做一个应该尽可能快的循环,我什至认为如果你做对了,它比调用 python api 函数更快。这样做,您甚至可以在不需要额外内存的情况下就地编辑数组。