1

From a masked 2d array like this: (x = --)

x x x x
x 5 6 x
x x x x
x x 9 x

How can I get: (confining the edges as much as possible until reaching a number)

5 6
x x 
x 9

Thanks.

4

2 に答える 2

0

スライスを使用してください:-)

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]
于 2013-05-28T08:53:26.280 に答える