[Numpy-discussion] Remove a random sample from array

josef.pktd at gmail.com josef.pktd at gmail.com
Mon May 16 23:00:07 EDT 2016


On Mon, May 16, 2016 at 12:24 PM, Elliot Hallmark <Permafacture at gmail.com>
wrote:

> Use `random.shuffle(range(len(arr))` to make a list of indices.  Use a
> slices to get your 20/80.  Convert to integer arrays and index your
> original array with them.  Use sorted on the 80% list if you need to
> preserve the order.
>

similar but simpler

You can just random permute/shuffle an array with 20% ones (True) and 80%
zeros (False) and use it as a mask to select from the original array.

Josef



>
>
> -Elliot
>
> On Mon, May 16, 2016 at 11:04 AM, Martin Noblia <
> martin.noblia at openmailbox.org> wrote:
>
>> I think with `np.random.choice`
>>
>>
>> http://docs.scipy.org/doc/numpy-dev/reference/generated/numpy.random.choice.html
>>
>>
>> On 05/16/2016 11:08 AM, Florian Lindner wrote:
>>
>> Hello,
>>
>> I have an array of shape (n, 2) from which I want to extract a random sample
>> of 20% of rows. The choosen samples should be removed the original array and
>> moved to a new array of the same shape (n, 2).
>>
>> What is the most clever way to do with numpy?
>>
>> Thanks,
>> Florian
>> _______________________________________________
>> NumPy-Discussion mailing listNumPy-Discussion at scipy.orghttps://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>> --
>> *Martin Noblia*
>>
>> _______________________________________________
>> NumPy-Discussion mailing list
>> NumPy-Discussion at scipy.org
>> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>>
>>
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> https://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20160516/034f6cd2/attachment.html>


More information about the NumPy-Discussion mailing list