Python ndarray padding

  • Post author:
  • Post category:python



Python ndarray padding


With the bug about


np.lib.pad


reported here:

https://github.com/numpy/numpy/issues/7353

and the corresponding update here:

https://github.com/numpy/numpy/pull/7354#issuecomment-189551370

We can get the proper padding for ndarray.

Demo code:

import numpy as np
import cv2

T = np.ones([150, 100, 200], dtype='uint8')
T = T*200
P = np.lib.pad(T, ((50, 50),(50, 50),(50, 50)), 'constant', constant_values=np.array(((100, 100),(100, 100),(100, 100))))

dim  = P.shape
print dim
for k in range(dim[2]):
    cv2.imshow('slice', P[:, :, k])
    cv2.waitKey(20)



版权声明:本文为yangyangyang20092010原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。