Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why has the numpy random.choice() function been discontinued?

I've been working with numpy and needed the random.choice() function. Sadly, in version 2.0 it's not in the random or the random.mtrand.RandomState modules. Has it been excluded for a particular reason? There's nothing in the discussion or documentation about it!

For info, I'm running Numpy 2.0 on python 2.7 on mac os. All installed from the standard installers provided on the sites.

Thanks!

like image 365
Alex S Avatar asked Feb 21 '12 09:02

Alex S


People also ask

What is NumPy random choice?

Definition of NumPy random choice. The NumPy random choice() function is used to gets the random samples of a one-dimensional array which returns as the random samples of NumPy array. The NumPy random choice() function is a built-in function in the NumPy package of python.

What is random rand () function in NumPy?

The numpy.random.rand() function creates an array of specified shape and fills it with random values. Syntax : numpy.random.rand(d0, d1, ..., dn) Parameters : d0, d1, ..., dn : [int, optional]Dimension of the returned array we require, If no argument is given a single Python float is returned.

Does NumPy have a random function?

numpy. random. rand() function is used to generate random values in the range of [0,1) . The data points form an uniform distribution.

How do I randomly select data in NumPy?

random. choice() function is used to get random elements from a NumPy array. It is a built-in function in the NumPy package of python.


1 Answers

random.choice is as far as I can tell part of python itself, not of numpy. Did you import random?

Update: numpy 1.7 added a new function, numpy.random.choice. Obviously, you need numpy 1.7 for it.

Update2: it seems that in unreleased numpy 2.0, this was temporarily called numpy.random.sample. It has been renamed back. Which is why when using unreleased versions, you really should have a look at the API (pydoc numpy.random) and changelogs.

like image 65
Has QUIT--Anony-Mousse Avatar answered Oct 21 '22 08:10

Has QUIT--Anony-Mousse