代码设计
import numpy as np
array_data=np.array([[1, 2, 3, 4, 5],
[0.1,0.2,0.3,0.4,0.5],
[-1, -2, -3, -4, -5]])
print(array_data.shape)
#批量对array数组数据进行替换、修改
#将array数组的矩阵数据限制到[0,1]范围内
array_data[array_data > 1] = 1
array_data[array_data == 0.5] = 0.501
array_data[array_data <= 0] = 1e-6
print(array_data)
输出结果
(3, 5)
[[1. 1. 1. 1. 1. ]
[0.1 0.2 0.3 0.4 0.501 ]
[0.000001 0.000001 0.000001 0.000001 0.000001]]
[[-0. -0. -0. -0. -0. ]
[ 2.30258509 1.60943791 1.2039728 0.91629073 0.69114918]
[13.81551056 13.81551056 13.81551056 13.81551056 13.81551056]]
[[-0. -0. -0. -0. -0. ]
[ 1.51742713 1.26863624 1.09725695 0.95723076 0.83135382]
[ 3.71692219 3.71692219 3.71692219 3.71692219 3.71692219]]