Skip to content
Justice Tech School

clip, minimum and maximum

clip limits values and minimum and maximum compare two arrays element-wise.

Example
a = np.array([-5, 3, 12, 8])
print(np.clip(a, 0, 10))
print(np.maximum(a, 0))
print(np.minimum(a, [1, 1, 1, 1]))

Result

[ 0  3 10  8]
[ 0  3 12  8]
[-5  1  1  1]

Exercise

Limit the range.

np.(a, 0, 10)

Quiz Test

Difference between max and maximum?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.