rng.integers() (or np.random.randint) lets you specify lists for low and high. So you can just use rng.integers((0,)*len(dims), dims).
Although I'm not seeing how to use this to generate a bunch of vectors at once. I would have thought something like size=(10, dims) would let you generate 10 vectors of length dims but it doesn't seem to work. Aaron Meurer On Fri, Nov 17, 2023 at 3:31 PM Stefan van der Walt via NumPy-Discussion <numpy-discussion@python.org> wrote: > > On Fri, Nov 17, 2023, at 11:07, Robert Kern wrote: > > If the arrays you are drawing indices for are real in-memory arrays for > present-day 64-bit computers, this should be adequate. If it's a notional > array that is larger, then you'll need actual arbitrary-sized integer > sampling. The builtin `random.randrange()` will do arbitrary-sized integers > and is quite reasonable for this task. If you want it to use our > BitGenerators underneath for clean PRNG state management, this is quite > doable with a simple subclass of `random.Random`: > https://github.com/numpy/numpy/issues/24458#issuecomment-1685022258 > > > Thanks, Robert. The use case is for randomly populating a hypothetical > N-dimensional sparse array object. > In practice, int64 will probably suffice. > > I can see how to generate arbitrarily large integers using the pattern above, > but still unsure how to sample without replacement. Aaron mentioned that > conflicts are extremely unlikely, so perhaps fine to assume they won't > happen. Checking for conflicts is expensive. > > Attached is a script that implements this solution. > > Stéfan > > _______________________________________________ > NumPy-Discussion mailing list -- numpy-discussion@python.org > To unsubscribe send an email to numpy-discussion-le...@python.org > https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ > Member address: asmeu...@gmail.com _______________________________________________ NumPy-Discussion mailing list -- numpy-discussion@python.org To unsubscribe send an email to numpy-discussion-le...@python.org https://mail.python.org/mailman3/lists/numpy-discussion.python.org/ Member address: arch...@mail-archive.com