lundi 4 septembre 2023

Shuffle array of array pyspark columns

I have pyspark column Like this:

                   gm_array
[[1, 4, 6,...], [2, 7, 8,...], [3, 5, 7,...],...]
[[8, 11, 9,...], [7, 2, 6,...], [10, 9, 8,...],...]
[[90, 13, 67,...], [55, 6, 98,...], [1, 6, 2,...],...]
.
.

Now I want to shuffle this single array and also array inside this array, and then I want to pick 5 first element from first 5 array.

1st Out which is randomly shuffle array:

                  gm_array
[[19, 6, 1,...], [9, 80, 5,...], [30, 7, 3,...],...]
[[7, 9, 11,...], [6, 8, 7,...], [18, 7, 10,...],...]
[[90, 1, 7,...], [8, 9, 81,...], [6, 5, 1,...],...]
.
.

2nd Out 1st element of 1st 5 array inside main array:

[19, 9, 30,...]
[7, 6, 18,...]
[[90, 8, 6,...]
.
.



Aucun commentaire:

Enregistrer un commentaire