lundi 14 juin 2021

Difference between shuffling a list of integers and a list of "lists of single integer"

I am studying a randomized algorithm for the Kaczmarz algorithm which solves any linear system Ax = b. In the python code, I am puzzled about the way of shuffling the array:

import random
x = [[i] for i in range(len(Im))] # Im is some numpy array of length ~30000
random.shuffle(x)
for rows in x:
    rows=rows[0]
    '''Code using the variable "rows" to pick corresponding matrix elements'''

May I ask is there any reason to create x with each integer element wrapped in a list? I found that the above implementation seems to be equivalent to

import random
x = [i for i in range(len(Im))] # Im is some numpy array of length ~30000
random.shuffle(x)
for rows in x:
    '''Code using the variable "rows" to pick corresponding matrix elements'''



Aucun commentaire:

Enregistrer un commentaire