numpy的:夹/切2D屏蔽数组
从掩蔽二维数组是这样的:(x = --)numpy的:夹/切2D屏蔽数组
x x x x x 5 6 x 
x x x x 
x x 9 x 
我怎样才能获得:(围边缘尽可能直到到达数)
5 6 x x 
x 9 
谢谢。
回答:
这应该做你想为一个通用的情况切片:
import numpy as np si, se = np.where(~x.mask) 
x = x[si.min():si.max() + 1, se.min():se.max() + 1] 
回答:
使用切片:-)
slice = x[1:, 1:-1] 您还可以修整边缘:
while all(x.mask[0, :]): x = x[1:, :] while all(x.mask[-1, :]): x = x[:-1, :] 
while all(x.mask[:, 0]): x = x[:, 1:] 
while all(x.mask[:, -1]): x = x[:, :-1] 
以上是 numpy的:夹/切2D屏蔽数组 的全部内容, 来源链接: utcz.com/qa/267075.html

