如何快速平滑阵列1000x1000

时间:2018-02-06 08:49:16

标签: python arrays python-2.7

我们正在模拟法国海湾(圣米歇尔山)的沉积,为此,我们将沉积物(以数字表示)放在一个阵列中。 我们的1000x1000阵列中存储是随机的,中间有一个岛。

在节目结束时,除了数字等于零的岛屿之外,我们希望在任何地方平滑我们的海湾。

我们做到了,但是跑得太久了。有人可以帮助我们找到加速我们计划的方法吗?

 mFloatingView = LayoutInflater.from(Services.this).inflate(R.layout.fragment_blank, null);
            final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.TYPE_PHONE,
                    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|WindowManager.LayoutParams.FLAG_FULLSCREEN|WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
                    PixelFormat.TRANSLUCENT);

            //Specify the view position
            params.gravity = Gravity.TOP | Gravity.LEFT;        
            params.x = 0;
            params.y = 100;

            //Add the view to the window
            mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
            mWindowManager.addView(mFloatingView, params);

1 个答案:

答案 0 :(得分:0)

我不能说这些循环的正确性。我只是将它们翻译成Numpy数组,所以它可以更具可读性。

import numpy as np

M = np.array(M)

diff = M[749:-1,:375]-M[750:,:375]
M[749:-1,:375][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[750:  ,:375][diff>=3] += np.floor(19*diff[diff>=3]/20)

diff = M[749:-1,625:]-M[750:,625:] # for the S-W of the bay
M[749:-1,625:][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[750:  ,625:][diff>=3] += np.floor(19*diff[diff>=3]/20)

diff = M[800:,200:-1]-M[800:,201:] # for the West of the bay
M[800:,200:-1][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[800:,201:  ][diff>=3] += np.floor(19*diff[diff>=3]/20)

diff = M[800:,1:800]-M[800:,:799] #Idem 
M[800:,1:800][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[800:, :799][diff>=3] += np.floor(19*diff[diff>=3]/20)

diff = M[501:851,:375]-M[500:850,:375] #Along the island
M[501:851,:375][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[500:850,:375][diff>=3] += np.floor(19*diff[diff>=3]/20)

diff = M[501:851,625:]-M[500:850,625:] #Idem
M[501:851,625:][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[500:850,625:][diff>=3] += np.floor(19*diff[diff>=3]/20)

diff = M[500:549,499:-2]-M[500:549,500:-1] #Idem
M[500:549,499:-2][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[500:549,500:-1][diff>=3] += np.floor(19*diff[diff>=3]/20)

diff = M[500:549,1:501]-M[500:549,:500] #Idem
M[500:549,1:501][diff>=3] -= np.floor(19*diff[diff>=3]/20)
M[500:549,:500][diff>=3] += np.floor(19*diff[diff>=3]/20)