What's this How to shuffle Numpy ndarray. The indexing of ndarray is for reference only, so you need to make a copy and then assign it.
shuffle_ndarray.py
import numpy
import random
#First, create a matrix appropriately
a = [
[1, 2, 3],
[5, 6, 7],
[9, 10, 11],
[12, 13, 14]
]
nda = numpy.array(a)
#Shuffle (twice the number of lines)
for i in range(nda.shape[0] * 2) :
index_a = random.randint(0, nda.shape[0]-1)
index_b = random.randint(0, nda.shape[0]-1)
#For reference, both will be the same element
#nda[index_a], nda[index_b] = nda[index_b], nda[index_a]
#Make a copy and then substitute each
nda[index_a], nda[index_b] = numpy.array(nda[index_b]), numpy.array(nda[index_a])