I have a data file like a two-dimensional array
22950 12
80044 22
02942 06
42018 20
63829 10
...
I want to shuffle this array into a random order, like
42018 20
22950 12
...
Looks like the ‘shuffle’ in List can be used to shuffle a vector, how to keep handle this kind of two-dimensional array?
Since you are only shuffling the first dimension of the array,
List::Util::shufflewill work without any modification.Perl does not have multi-dimentional arrays, it has arrays of scalars, each of which can also be an array. This is effectively a multi-dimentional array, but it means that you can use normal array operations like
shuffle, sinceshuffledoes not care what the values of the array are (and in this case they will be other arrays).so the line:
is the same as
as far as
shuffleis concerned (a list of 3 elements to shuffle).so assuming your 2D data is contained in the array
@datathen you would just write:
and then you would access the 2D structure normally: