You can create random indices with np.random.choice
:
n = 2 # for 2 random indices
index = np.random.choice(X.shape[0], n, replace=False)
Then you just need to index your arrays with the result:
x_random = X[index]
y_random = Y[index]
More Related Contents:
- How to print the full NumPy array, without truncation?
- Convert Python sequence to NumPy array, filling missing values
- Numpy array assignment with copy
- numpy matrix vector multiplication [duplicate]
- Repeating each element of a numpy array 5 times
- how does multiplication differ for NumPy Matrix vs Array classes?
- Ambiguity in Pandas Dataframe / Numpy Array “axis” definition
- How to split/partition a dataset into training and test datasets for, e.g., cross validation?
- How to create a numpy array of arbitrary length strings?
- Numpy modify array in place?
- Subsetting a 2D numpy array
- How to normalize a 2-dimensional numpy array in python less verbose?
- What is the difference between ndarray and array in NumPy?
- Removing elements from an array that are in another array
- Creating same random number sequence in Python, NumPy and R
- Stocking large numbers into numpy array
- check for identical rows in different numpy arrays
- pd.Timestamp versus np.datetime64: are they interchangeable for selected uses?
- Numpy: For every element in one array, find the index in another array
- Prevent numpy from creating a multidimensional array
- Concatenate range arrays given start, stop numbers in a vectorized way – NumPy
- Inverting a numpy boolean array using ~
- Numpy minimum in (row, column) format
- Convert NumPy array to 0 or 1 based on threshold
- Cannot understand numpy argpartition output
- Using numpy ‘module’ object has no attribute ‘array’ [duplicate]
- Python: Split NumPy array based on values in the array
- Python, OpenCV: Increasing image brightness without overflowing UINT8 array
- Add single element to array in numpy
- Efficient dot products of large memory-mapped arrays