# Np.delete unexpected behaviour in an njit funcion

**URL:** <https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388>\
**Category:** Numba\
**Created:** [December 9, 2020, 11:54am UTC](https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388 "2020-12-09T11:54:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaistech-sp](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/jaistech-sp/32/165_2.png) [@jaistech-sp](https://numba.discourse.group/u/jaistech-sp)\
**Post date:** [December 9, 2020, 11:54am UTC](https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388/1 "2020-12-09T11:54:46Z")

</div>

Hello!  
Amazing job with the numba version 0.52.0, I would like to report what seems to be an unexpected behaviour (in my limited experience)

```auto
a = np.asarray([[1,2,-3,-3,4],[0,0,0,0,0]])
#This works without njiting
@njit
def fii(arr, val):
    return np.delete(arr, np.where(arr==val))
fii(a, -3)

```

The point is that with arr (input arr) is a 1D array; njited fii() only works if np.where does not return the tuple ([whatever indexes],)

```auto
'''this works:'''
a = np.asarray([1,2,-3,-3,4])
#Does not work if you don't delete the tuple returned by np.where
@njit
def fii(arr, val):
    return np.delete(arr, np.where(arr==val)[0])
fii(a, -3)

```

If using numpy, it works correctly in all the cases, is this something expected?

Thanks a lot and congrats on your amazing job!

---

<div class="post-metadata">

**Author:** ![esc](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/esc/32/49_2.png) [@esc](https://numba.discourse.group/u/esc)\
**Post date:** [December 10, 2020, 1:13pm UTC](https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388/2 "2020-12-10T13:13:10Z")

</div>

Hi and thank you for your kind words. We do appreciate your feedback! Could you perhaps elaborate on the results you expect and what you see instead. I.e. what does “does not work” mean?

---

<div class="post-metadata">

**Author:** ![jaistech-sp](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/jaistech-sp/32/165_2.png) [@jaistech-sp](https://numba.discourse.group/u/jaistech-sp)\
**Post date:** [December 11, 2020, 11:40am UTC](https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388/3 "2020-12-11T11:40:28Z")

</div>

Hi Esc, and thanks! I would like these two njitted function to work:

```auto
a = np.asarray([[1,2,-3,-3,4],[0,0,0,0,0]])
#This works without njiting
@njit
def fii(arr, val):
    return np.delete(arr, np.where(arr==val))

b = np.asarray([1,2,-3,-3,4])
@njit
def fee(arr, val):
    return np.delete(arr, np.where(arr==val))# [0]

fii(a,-3)
fee(b, -3)

```

---

<div class="post-metadata">

**Author:** ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)\
**Post date:** [December 11, 2020, 5:44pm UTC](https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388/4 "2020-12-11T17:44:20Z")

</div>

Hi @jaistech-sp,

I think Numba is implementing the specification:  
[https://numpy.org/doc/stable/reference/generated/numpy.delete.html](https://numpy.org/doc/stable/reference/generated/numpy.delete.html)  
where the second argument, `obj`, is described as:

> **obj** slice, int or array of ints

and in the case presented `np.where` is returning a `tuple` or `np.ndarray`. I think NumPy is dealing with this by doing `asarray` followed by `ravel`:

> <https://github.com/numpy/numpy/blob/v1.19.0/numpy/lib/function_base.py#L4308-L4317>

I suggest opening a feature request on Numba’s issue tracker if this is important to you. It could well require clarification from NumPy before a fix is made. As a work around, can you just do the indexing for now?

Hope this helps?

---

<div class="post-metadata">

**Author:** ![jaistech-sp](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/jaistech-sp/32/165_2.png) [@jaistech-sp](https://numba.discourse.group/u/jaistech-sp)\
**Post date:** [December 14, 2020, 10:06am UTC](https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388/5 "2020-12-14T10:06:24Z")

</div>

Hi Stuart,  
Thanks a lot for the replay, somehow I figure it out like raveling the array and reshaping. Please let me know if it worth for Numba to have an open issue on that topic and I will do so.

---

<div class="post-metadata">

**Author:** ![stuartarchibald](https://yyz2.discourse-cdn.com/free1/user_avatar/numba.discourse.group/stuartarchibald/32/10_2.png) [@stuartarchibald](https://numba.discourse.group/u/stuartarchibald)\
**Post date:** [December 14, 2020, 11:13am UTC](https://numba.discourse.group/t/np-delete-unexpected-behaviour-in-an-njit-funcion/388/6 "2020-12-14T11:13:11Z")

</div>

@jaistech-sp no problem. You are most welcome to open an issue if it’s important to you. Thanks.
