np.random.shuffle: "Modify a sequence in-place by shuffling its contents." Matches doc string:
a = np.arange(10) np.random.shuffle(a[:-1]) a array([0, 7, 8, 4, 3, 6, 2, 1, 5, 9])
Doesn't match doc string:
l = range(10) np.random.shuffle(l[:-1]) l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Is there any way for numpy to catch this?
On Sat, May 29, 2010 at 13:35, Keith Goodman <kwgoodman@gmail.com> wrote:
np.random.shuffle: "Modify a sequence in-place by shuffling its contents."
Matches doc string:
a = np.arange(10) np.random.shuffle(a[:-1]) a array([0, 7, 8, 4, 3, 6, 2, 1, 5, 9])
Doesn't match doc string:
l = range(10) np.random.shuffle(l[:-1]) l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
This behavior does match the doc-string. l[:-1] creates a new list unconnected to the original list. np.random.shuffle() then shuffles that new list in-place.
Is there any way for numpy to catch this?
Nope. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
On Sat, May 29, 2010 at 11:45 AM, Robert Kern <robert.kern@gmail.com> wrote:
On Sat, May 29, 2010 at 13:35, Keith Goodman <kwgoodman@gmail.com> wrote:
np.random.shuffle: "Modify a sequence in-place by shuffling its contents."
Matches doc string:
a = np.arange(10) np.random.shuffle(a[:-1]) a array([0, 7, 8, 4, 3, 6, 2, 1, 5, 9])
Doesn't match doc string:
l = range(10) np.random.shuffle(l[:-1]) l [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
This behavior does match the doc-string. l[:-1] creates a new list unconnected to the original list. np.random.shuffle() then shuffles that new list in-place.
Is there any way for numpy to catch this?
Nope.
The best way to remember something is to turn it into a dumb question and then post to a large mailing list. Make sure not to use an alias.
participants (2)
-
Keith Goodman
-
Robert Kern