我想了解以下Python細分。關於設置ogrid和fillup在numpy中相應的多維數組
def upsample_filt(size):
factor = (size + 1) // 2
if size % 2 == 1:
center = factor - 1
else:
center = factor - 0.5
og = np.ogrid[:size, :size]
return (1 - abs(og[0] - center)/factor) * \
(1 - abs(og[1] - center)/factor)
根據numpy
,ogrid returns a mesh-grid ndarrys with only one dimension.I think the program want to generate
尺寸*尺寸array. Why is it be written as
OG = np.ogrid [:大小,:尺寸] Or what does
:size`意思?
作爲一個測試,我設置size=4
,並且print((1 - abs(og[0] - center)/factor)*(1 - abs(og[1] - center)/factor))
,輸出如下:
[[ 0.0625 0.1875 0.1875 0.0625]
[ 0.1875 0.5625 0.5625 0.1875]
[ 0.1875 0.5625 0.5625 0.1875]
[ 0.0625 0.1875 0.1875 0.0625]]
我不是很清楚怎麼做(1 - abs(og[0] - center)/factor)*(1 - abs(og[1] - center)/factor)
fillup這個多維數組?
感謝您的解釋。 – user297850