I have a large matrix, 4000x4000 I need to calculate the local average window value of 11x11 for each x, y of this matrix. Usually it should be something like
for x in range(4000) for y in range(4000) b[x,y]=mean(a[x-5:x+5,y-5:y+5]
But it will last a lot of time. Is this a more efficient way to do this? Thank you
You essentially need a two-dimensional convolution. Scipy can do this for you: http://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.convolve2d.html
, SO: 2d python numpy
, . , -, , ( ), ( ), , .
for x in xrange(4000): for y in xrange(4000): c[x,y] = a[x,y] if x > 0: c[x,y] += c[x-1,y] if y > 0: c[x,y] += c[x,y-1]
, : . 11x11
c[x+5,y+5]-c[x-5,y-5]
, :
b[x,y] = (c[x+5+,y+5]-c[x-5,y-5])/121
121 2 .
Source: https://habr.com/ru/post/1772670/More articles:How to save the state of an audio file when a user pauses my application? - objective-cThe activity window on the standard call screen - "Enable" buttons - androidWhat did I put into the dict visit passed to my __deepcopy__ custom function? - pythonПо умолчанию загружайте некоторые данные в нашу базу данных sqlite - androidГраница изображения в строгом HTML с использованием CSS - htmlDjango: CSRF check failed - djangoUsing AutoMapper in POCO? - c #How easy is it to test Java classes? - javaUnzip a string with hexadecimal - pythonT-SQL Check for duplicate field1 values but different field2 values - sqlAll Articles