Issue 1:
Original ticket http://projects.scipy.org/numpy/ticket/1036 on 2009-03-04 by @rc, assigned to @rc.

Neil Crighton wrote:

As far as I know there isn't an obvious way to get the functionality of setmember1d working on non-unique inputs. However, I've needed this operation quite a lot, so here's a function I wrote that does it. It's only a few times slower than numpy's setmember1d. You're welcome to use it.

import numpy as np

def ismember(a1,a2):
""" Test whether items from a2 are in a1.

This does the same thing as np.setmember1d, but works on
non-unique arrays.

Only a few (2-4) times slower than np.setmember1d, and a lot
faster than [i in a2 for i in a1].

An example that np.setmember1d gets wrong:

>>> a1 = np.array([5,4,5,3,4,4,3,4,3,5,2,1,5,5])
>>> a2 = [2,3,4]
>>> mask = ismember(a1,a2)
>>> a1[mask]
array([4, 3, 4, 4, 3, 4, 3, 2])
"""
a2 = set(a2)
a1 = np.asarray(a1)
ind = a1.argsort()
a1 = a1[ind]
mask = []
# need this bit because prev is not defined for first item
item = a1[0]
if item in a2:
mask.append(True)
a2.remove(item)
else:
mask.append(False)
prev = item
# main loop
for item in a1[1:]:
if item == prev:
mask.append(mask[-1])
elif item in a2:
mask.append(True)
prev = item
a2.remove(item)
else:
mask.append(False)
prev = item
# restore mask to original ordering of a1 and return
mask = np.array(mask)
return mask[ind.argsort()]

Issue 2:
Describe the issue:

A simple code snippet below calculating bins for a given input fails while trying to allocate 12.7 PiB of RAM. Probably related to my floats precision, but is definitely not the expected result.

I would be most grateful if anyone could suggest a workaround while this bug is being fixed.

Reproduce the code example:

import numpy as np
x = np.array([6.3,
6.3,
7.399999999999999,
7.399999999999999,
7.399999999999999,
7.399999999999999,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.4,
7.407142857142857,
7.407142857142857,
7.4125,
7.4125])
np.histogram(x, density=True, bins="auto")

Error message:

Traceback (most recent call last):
File "/Users/user/miniforge3/envs/clients/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3433, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "<ipython-input-3-f76ea541d063>", line 25, in <module>
np.histogram(x, density=True, bins="auto")
File "<__array_function__ internals>", line 180, in histogram
File "/Users/user/miniforge3/envs/clients/lib/python3.8/site-packages/numpy/lib/histograms.py", line 793, in histogram
bin_edges, uniform_bins = _get_bin_edges(a, bins, range, weights)
File "/Users/user/miniforge3/envs/clients/lib/python3.8/site-packages/numpy/lib/histograms.py", line 446, in _get_bin_edges
bin_edges = np.linspace(
File "<__array_function__ internals>", line 180, in linspace
File "/Users/user/miniforge3/envs/clients/lib/python3.8/site-packages/numpy/core/function_base.py", line 135, in linspace
y = _nx.arange(0, num, dtype=dt).reshape((-1,) + (1,) * ndim(delta))
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 12.7 PiB for an array with shape (1781062197026280,) and data type float64

NumPy/Python version information:

1.23.3 3.8.15 | packaged by conda-forge | (default, Nov 22 2022, 08:49:06)

[Clang 14.0.6 ]

Context for the issue:

No response