Add clip() utility function to Base

In Python this is a handy operation on arrays:

Is there a function in Julia for achieving the same result? If not, can I open an issue on GitHub with a feature request?

1 Like

Perhaps this is what you are looking for

help?> clamp
search: clamp clamp!

  clamp(x, lo, hi)

  Return x if lo <= x <= hi. If x < lo, return lo. If x > hi, return hi.
  Arguments are promoted to a common type. Operates elementwise over x if x is
  an array.

Perfect, I still don’t understand how can I mark questions as solved on Discourse, sometimes I have the option, sometimes I don’t. Do I need to tag the thread with question?

@kristoffer.carlsson how to mark the question as solved? I want to mark it myself next time.

Well, I didn’t mark anything so I thought you did. Maybe someone with mod power did. I’m not sure how to mark as solution, I thought there was a button under each post you could click.

Sorry, I think it was @ihnorton that marked it? I got a notification in the upper right saying that my post was edited by him. Only admin can mark as solved?

I created a new topic for this question, it turns out it is important: