1. Home
  2. Data Science
  3. NumPy
  4. What does the np.clip() function do in NumPy?

Added 24 Feb 2024

What does the np.clip() function do in NumPy?

  1. Clips values outside a specified range to the range's boundaries Correct answer
  2. Rounds the elements of an array to the nearest integer
  3. Calculates the cumulative sum of elements along a specified axis
  4. Computes the natural logarithm of the elements of an array

Correct answer

A. Clips values outside a specified range to the range's boundaries

16 views

MCQSEXAM

Explanation

np.clip() limits values to a given range: anything below the minimum becomes the minimum and anything above the maximum becomes the maximum. np.clip([1, 5, 12], 2, 10) returns [2, 5, 10].

It is commonly used to cap outliers or keep pixel values within 0–255.

Want more practice? Try the full set of Data Science MCQs on MCQsExam.com.

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More NumPy MCQs

Practise all NumPy MCQs

Similar MCQs