util.py 文件源码

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

项目:wxgen 作者: metno 项目源码 文件源码
def resize(vec, size):
   """
   Resizes a vector such that it has the right size. This is done by repeating the vector
   in each dimension until the required size is reached. Note an error is thrown if 'size'
   is not a multiple of the size of vec.

   vec      A 1D or 2D numpy array
   size     A list of dimension sizes (e.g. [2,3])
   """
   if not isinstance(vec, (np.ndarray)):
      vec_resized = vec * np.ones(size)
   elif vec.shape[0] == size[0] and len(vec.shape) == 1:
      vec_resized = np.reshape(np.repeat(vec, size[1]), size)
   elif vec.shape[0] == 1 and len(vec.shape) == 1:
      vec_resized = vec*np.ones(size)
   else:
      # Check that the output dims are multiples of input dims
      assert(size[0] % vec.shape[0] == 0)
      assert(size[1] % vec.shape[1] == 0)
      vec_resized = np.tile(vec, (size[0] // vec.shape[0], size[1] // vec.shape[1]))
   return vec_resized
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号