Is there a “bounding box” function (slice with non-zero values) for a ndarray in NumPy?

后端 未结 3 829
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 11:06

I am dealing with arrays created via numpy.array(), and I need to draw points on a canvas simulating an image. Since there is a lot of zero values around the central part of

3条回答
  •  [愿得一人]
    2020-12-10 11:53

    Something like:

    empty_cols = sp.all(array == 0, axis=0)
    empty_rows = sp.all(array == 0, axis=1)
    

    The resulting arrays will be 1D boolian arrays. Loop on them from both ends to find the 'bounding box'.

提交回复
热议问题