part1.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:MOOCs 作者: ankitaggarwal011 项目源码 文件源码
def make_gaussian(k, std):
  '''Create a gaussian kernel.

  Input:

  k - the radius of the kernel.

  std - the standard deviation of the kernel.

  Output:

  output - a numpy array of shape (2k+1, 2k+1) and dtype float.

  If gaussian_1d is a gaussian filter of length 2k+1 in one dimension, 
  kernel[i,j] should be filled with the product of gaussian_1d[i] and 
  gaussian_1d[j].

  Once all the points are filled, the kernel should be scaled so that the sum
  of all cells is equal to one.'''
  kernel = None
  # Insert your code here.----------------------------------------------------
  kernel=np.zeros((2*k+1,2*k+1),dtype=np.float)
  gaussian_1d = signal.gaussian(2*k+1,std)
  for i in range(gaussian_1d.shape[0]):
    for j in range(gaussian_1d.shape[0]):
      kernel[i,j]=gaussian_1d[i]*gaussian_1d[j]
  kernelsum = kernel.sum()
  kernel = kernel/kernelsum
  #---------------------------------------------------------------------------
  return kernel
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号