SoFunction
Updated on 2024-11-14

Python implementation to randomly fetch certain rows of a matrix array

Without further ado, let's get straight to the code!

import numpy as np
 
array = ([0, 0])
for i in range(10):
  array = ((array, [i+1, i+1]))
print(array)
# [[ 0 0]
# [ 1 1]
# [ 2 2]
# [ 3 3]
# [ 4 4]
# [ 5 5]
# [ 6 6]
# [ 7 7]
# [ 8 8]
# [ 9 9]
# [10 10]]
 
rand_arr = ([0])
 
(rand_arr)
print(array[rand_arr[0:5]])
# [[9 9]
# [4 4]
# [1 1]
# [5 5]
# [8 8]]
(rand_arr)
print(array[rand_arr[0:5]])
# [[10 10]
# [ 3 3]
# [ 4 4]
# [ 8 8]
# [ 5 5]]

Above this Python implementation to randomly take a matrix array of a few rows is all that I have shared with you, I hope to be able to give you a reference, and I hope you will support me more.