How to select element randomly from a numpy array in Python

5 means we have indices from 0 to 4.

n means number of random indices.

Then if A is an array, first we need to generate random indices among all A indices like

Then we can select the elements from A corresponding to those random indices.

Sample:

Posting about Python and Laravel

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Laravel 9 vs Laravel 8: What Has Changed In Laravel 9

Android Network Requests and battery drain

Setting Up a Raspberry Pi Web Kiosk

Raspberry Pi and Embedded Linux Adventure (PART1: How to Start)

Getting Started with minikube

Playing spot the difference with PDFs

Learning to code by creating your own #EduBreakout

How Good Developers Fix Vulnerable Apps?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Panjeh

Panjeh

Posting about Python and Laravel

More from Medium

Arduino Coding In js client agent

Picture of arduino

Chapter 14 : Images

Steps to Install Environment for Angular Web Development

Creating a Simple IoT Project