numpy
これを非常に簡単に行うために使用できます。
import numpy as np
a = [range(255) for _ in range(10)]
np_a = np.array(a)
# set all values above 200 to 0
np_a[np_a > 200] = 0
# np_a now contains the data with all values above 200 changed to 0
# if you needed to convert the numpy array back to a python list
a = np_a.tolist()
動作していることを示す出力。
In [209]: np_a
Out[209]:
array([[ 0, 1, 2, ..., 252, 253, 254],
[ 0, 1, 2, ..., 252, 253, 254],
[ 0, 1, 2, ..., 252, 253, 254],
...,
[ 0, 1, 2, ..., 252, 253, 254],
[ 0, 1, 2, ..., 252, 253, 254],
[ 0, 1, 2, ..., 252, 253, 254]])
In [210]: np_a[np_a > 252] = 0
In [211]: np_a
Out[211]:
array([[ 0, 1, 2, ..., 252, 0, 0],
[ 0, 1, 2, ..., 252, 0, 0],
[ 0, 1, 2, ..., 252, 0, 0],
...,
[ 0, 1, 2, ..., 252, 0, 0],
[ 0, 1, 2, ..., 252, 0, 0],
[ 0, 1, 2, ..., 252, 0, 0]])