慕容森
您可以使用np.where:matrix = np.array([[[0,0.5,0.6],[0.9,1.2,0]],[[0,0.5,0.6],[0.9,1.2,0]]])matrix[np.where((matrix > 0.55) & (matrix < 0.95))] = 0.55# Or# matrix[(matrix > 0.55) & (matrix < 0.95)] = 0.55输出:>>> matrixarray([[[0. , 0.5 , 0.55], [0.55, 1.2 , 0. ]], [[0. , 0.5 , 0.55], [0.55, 1.2 , 0. ]]])