您可以如下计算:
>>> data = np.random.random_sample((200, 300, 100)) > 0.5>>> data.any(axis=-1).shape # show the result has the shape we want(200, 300)>>> data.any(axis=-1)array([[ True, True, True, ..., True, True, True], [ True, True, True, ..., True, True, True], [ True, True, True, ..., True, True, True], ..., [ True, True, True, ..., True, True, True], [ True, True, True, ..., True, True, True], [ True, True, True, ..., True, True, True]], dtype=bool)>>>
您可以根据需要缩放值
>>> data.any(axis=-1) * 255array([[255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255], ..., [255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255], [255, 255, 255, ..., 255, 255, 255]])>>>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)