小编Mis*_*ing的帖子

是否可以对访问numpy数组中不同元素的函数进行矢量化?

假设我希望在python中实现以下代码

此函数将图像作为一维数组,并迭代数组中的各个元素(输入图像中的像素),这会影响输出数组,该输出数组也是表示为一维数组的图像

示例:输入图像中的单个像素(红色)影响(橙色)中的8个周围像素 例1

C中的基本实现是

/* C version 
 * Given an input image create an 
 * output image that is shaped by individual pixels
 * of the input image
 */

int image[width * height]; //image retrieved elsewhere
int output [width * height]; //output image
int y = 0, x = 0;
for( y = 1; y < height-1 ; ++ y) {
    for(x = 1; x < width-1; ++ x) {
        if (image[y * width + x] > condition) {
            /* …
Run Code Online (Sandbox Code Playgroud)

python arrays numpy vectorization

5
推荐指数
2
解决办法
240
查看次数

标签 统计

arrays ×1

numpy ×1

python ×1

vectorization ×1