question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

numpy.clip accept numpy.array for a_max

See original GitHub issue

Hi Numba team, Thanks for your contributions. Please could you add support of numpy.clip() so that it can accept a numpy.array() as the a_max and a_min?

The example code below works when running normally, but does not work when using @njit.

mask = a > b; out[mask] = (np.clip(c, 0, d)[mask]) where mask is a boolean of length 1000 c.shape = (1000, 10, 10) d.shape = (1000, 10, 10) (i.e. not just a number)

I get this error when running with @jit(nopython=True) "numba.core.errors.TypingError: Failed in nopython mode pipeline (step: nopython frontend) No implementation of function Function(<function clip at 0x000001F8477D5C10>) found for signature:

clip(array(float64, 3d, C), Literalint, array(int32, 3d, C))

There are 2 candidate implementations:

  • Of which 2 did not match due to: Overload in function ‘np_clip’: File: numba\np\arrayobj.py: Line 1805. With argument(s): ‘(array(float64, 3d, C), int64, array(int32, 3d, C))’: Rejected as the implementation raised a specific error: TypingError: The argument “a_max” must be a number"

Feature request

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
czgdp1807commented, Apr 2, 2022

I think I can work on this. Please let me know if that’s okay.

Edit 1 - I figured that we first need to implement, np.broadcast because a can be a scalar as well in which case we need an easy to implement broadcasting all the inputs to the same shape before starting to iterate on the inputs.

Edit 2 - I checked, @guilhermeleobas has recently implemented np.broadcast_arrays, so it should be possible to implement this feature. So, may be I can proceed with enhancing numpy.clip? Please let me know.

0reactions
Twomemcommented, Apr 4, 2022

Great, thanks @czgdp1807 !

Read more comments on GitHub >

github_iconTop Results From Across the Web

NumPy: Limit ndarray values to min and max with clip()
To limit the values of the NumPy array ndarray to given range, use np.clip() or clip() method of ndarray.By specifying the minimum and ......
Read more >
numpy.clip — NumPy v1.24 Manual
Clip (limit) the values in an array. Given an interval, values outside the interval are clipped to the interval edges. For example, if...
Read more >
NumPy clip(): Limit Array Values with Min and Max - Datagy
The NumPy clip() function will clip, or limit, the values in an array. This allows you to set a lower and/or upper limit...
Read more >
How to Use NumPy clip() in Python - Spark by {Examples}
NumPy clip () function in Python is used to clip(limit) the elements in an array. In the clip() function, pass the interval(combination of ......
Read more >
How do I add a value at specific indices in a numpy array with ...
Try np.clip() Something like import numpy as np array = np.array([-10,0,1,2,100,200,300]) min = 0 max = 255 np.clip(array, min, max).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found