替换Python NumPy数组中所有大于某个值的元素
我有一个2D NumPy数组,并希望将大于或等于阈值T的所有值替换为255.0。据我所知,最基本的方法是: shape = arr.shape result = np.zeros(shape) for x in range(0, shape[0]): for y in range(0, shape[1]): if arr[x, y] >= T: result[x, y] = 255 什么是最简洁,最pythonic的方法? 有更快的方法(可能不太简洁和/或更少的pythonic)来做到这一点吗? 这将是用于人头MRI扫描的窗口/水平调整子程序的一部分。2D numpy数组是图像像素数据。