samedi 27 février 2021

Shuffling a list returns None

I have a nested list whose each element contains 5 elements two of which are string, 2 others are arrays and the other one is an integer. This is an example of one of the elements:

print(data[0])

['string1', 'string2', array([ 8.3815563e-01, -3.5425583e-01,  2.1343436e+00,  9.6825659e-02,
       -9.0467620e-01,  2.3725919e-01, -1.1198132e+00, -1.4628445e+00,
       -9.7618866e-01,  3.4088433e-01, -8.1933931e-02,  5.3724372e-01,
       -9.3491834e-01, -1.7797737e-01, -2.3983700e+00,  2.8213045e-01,
       -2.6180375e+00, -1.3855113e+00,  5.4659176e-01,  9.1559738e-01,
       -9.5645869e-01,  1.1714146e+00, -1.5016689e+00, -6.0279185e-01,
       -2.7174740e+00, -8.4398395e-01, -1.4227449e+00, -3.3634397e-01,
       -1.1180943e-01,  2.0590048e+00, -8.1385499e-01,  3.3400309e-01,
        1.5486939e+00,  7.1667129e-01, -5.3015262e-01,  2.9040620e-01,
       -1.7378879e+00,  1.8073572e+00,  2.0475891e+00, -3.7024517e-02,
       -2.4894023e+00,  8.1641458e-02, -1.0466967e+00, -9.3819243e-01,
        2.2070546e+00, -7.8535575e-01,  1.8938659e+00,  6.1495984e-01,
        1.3074586e+00,  1.7998766e+00,  4.2521158e-01, -1.0011816e+00,
        3.9505896e-01,  1.9510569e-01,  5.4488051e-01, -2.4220757e+00,
       -2.0812688e+00,  7.4905115e-01,  2.5282860e+00,  3.6349185e+00,
       -1.5371487e-02, -1.4186651e+00, -3.0352873e-01,  1.1874241e+00,
       -7.4466765e-01, -5.5792803e-01,  2.0802140e+00, -1.0457656e+00,
       -1.6084572e+00,  7.6335722e-01,  6.1364901e-01, -8.8677669e-01,
        1.8135322e+00, -9.9430311e-01,  1.1136630e+00,  1.7036382e+00,
        1.2363054e+00, -1.0278525e+00, -1.4202880e+00,  3.4898412e+00,
        3.2176024e-01, -3.3177676e+00, -1.5177081e+00, -3.3506298e+00,
        8.9109224e-01, -9.2560369e-01, -1.3482516e-01,  1.8940198e+00,
       -2.4911180e+00,  1.7098404e+00,  1.0733328e+00, -6.8110102e-01,
        7.5147294e-02,  2.0663846e+00, -6.3406414e-01, -8.0714762e-01,
       -3.9137515e-01,  1.6869707e+00,  1.8897502e+00, -1.0949643e+00,
        8.3844274e-02, -3.1892413e-01,  1.0630800e+00, -2.1269834e-02,
        3.3197129e+00, -1.1836429e+00,  1.2935223e-01,  1.2349771e+00,
       -1.7768501e-01, -8.5823111e-02,  9.8761206e-04, -3.3543497e-01,
        1.2038582e-01,  1.0106378e+00, -6.1783981e-01,  6.3571078e-01,
        3.6776218e+00, -1.0869727e+00,  4.0498915e-01, -1.3616250e+00,
       -1.9101478e+00, -1.4676404e+00,  5.2525636e-02, -9.4835764e-01,
       -2.2515597e+00, -1.4384656e+00,  2.7463729e+00, -1.1626251e+00,
        5.0647104e-01, -1.0085446e+00, -3.4135873e+00,  2.8761895e+00,
       -7.5525141e-01,  1.9556025e-01,  1.8816977e+00, -2.1862485e+00,
        5.3653735e-01,  1.0174786e+00, -3.5168248e-01,  1.4792174e+00,
       -1.9718715e+00,  3.5284543e-01, -1.3289005e+00,  9.2077084e-02,
       -1.5259730e+00, -1.2676430e-01,  6.3915849e-02,  5.7076526e-01,
       -1.4283143e+00,  3.4811370e+00, -7.5676990e-01,  1.5901275e-01,
        3.0968320e-01, -2.0210378e+00,  1.5994365e+00, -1.8184477e+00,
       -1.7792468e+00, -3.8709867e+00, -8.5106057e-01,  7.5884897e-01,
        3.2979882e-01, -1.5201263e-01, -1.9805571e+00, -2.2941742e+00,
       -4.1824151e-02, -2.1928535e+00, -1.8360862e-01,  9.7463828e-01,
        6.0613501e-01,  1.4130658e+00,  1.2847931e+00, -1.3037770e+00,
       -9.3676001e-01,  1.6299471e+00,  2.8797865e+00,  7.8968775e-01,
       -4.1697282e-01, -7.7608454e-01, -8.9482792e-02, -1.5818343e-01,
        6.1421517e-02,  1.3762995e+00, -1.6491550e+00,  3.0861428e-01,
        4.6627381e-01,  1.6797400e+00,  7.4473983e-01, -2.0260219e-01,
       -1.2619594e+00, -9.3980944e-01,  1.4026953e+00,  4.5976865e-01,
       -1.7153995e+00, -1.5826430e+00,  4.1946498e-01, -2.3856725e-01,
       -7.2106045e-01, -4.1541594e-01,  2.0517633e+00,  1.4137658e+00],
      dtype=float32), array([ 0.76214266, -1.1080794 ,  0.62450695, -0.03991625, -1.0332664 ,
        0.4477847 , -1.5307423 , -0.46780497, -0.65694493,  0.4017106 ,
        1.046495  ,  0.89560634, -0.02834422,  0.25185633, -1.722349  ,
        0.47461596,  0.43950516,  0.47719032,  1.231193  , -0.2833851 ,
       -0.95124   ,  1.9791093 , -2.199751  , -0.31563753, -0.15620655,
        0.08995419, -1.0236559 , -0.09124855,  1.3184121 ,  1.3093723 ,
        1.5500983 , -1.138387  ,  1.825099  ,  0.54720974, -0.4497883 ,
       -1.019564  , -0.4743175 ,  1.5091532 ,  2.434069  , -0.51617134,
       -1.3287805 , -0.9675629 ,  1.0409877 ,  0.24908057,  1.448763  ,
        0.75647604,  0.25115636,  1.0880857 ,  0.44079414,  2.5577083 ,
        0.13774393, -0.7663842 ,  0.39448643,  1.6326874 ,  1.7713975 ,
       -1.0623255 , -0.27031946, -2.0021632 ,  1.4890292 ,  0.4731933 ,
       -0.30264556,  1.0804956 , -1.607742  ,  0.9306975 ,  0.12114237,
       -0.62948585,  0.52928966, -0.93153584,  1.3739216 ,  0.5499291 ,
        1.8106089 , -0.83994585,  0.287617  ,  1.7036526 ,  1.045847  ,
        1.971305  ,  0.94189185,  0.37291932, -1.2711267 ,  1.4045115 ,
        0.6248116 , -1.5587406 , -0.43730614, -2.5828342 , -0.5555636 ,
       -0.8796892 , -1.9538026 , -0.03389208,  0.3284353 , -0.12875274,
        0.65289074, -0.6155094 ,  0.28595057,  0.68420696, -0.5966044 ,
        0.5173465 , -0.76814157,  0.5442661 , -0.7675229 , -0.5273055 ,
        0.6800498 , -0.51253283, -0.7812486 , -0.38429317,  0.7641112 ,
       -0.01918199, -0.6239758 ,  1.5667789 ,  1.4919078 , -0.65991163,
       -1.4864634 , -1.0146723 ,  0.6918642 ,  0.44775197, -0.14802925,
        1.762855  ,  1.1468196 , -0.37504146, -0.32759622, -2.2596357 ,
       -1.1980705 , -1.4669111 , -0.09373622, -0.34457773, -1.4592841 ,
       -0.06391117,  0.6223186 , -0.321511  ,  0.30783862, -1.0348482 ,
       -0.70685714,  1.2692565 ,  0.21873838,  1.0072349 , -0.5244955 ,
       -0.8728946 , -0.03604483,  1.4866482 , -0.7006194 ,  2.59386   ,
        0.04309946,  0.8236084 , -1.192761  ,  0.91982   , -0.2588019 ,
        0.46571994,  1.0871515 , -1.3756664 , -1.5655178 ,  0.45953277,
        0.74666524,  0.38552722,  1.7726213 , -0.3308338 ,  0.5287637 ,
       -1.8667183 ,  0.65863764,  0.18299544,  0.6244534 , -0.5654262 ,
        0.3377428 , -0.91572076, -1.8910241 , -1.1871653 ,  0.94825065,
       -1.4711756 , -0.8371643 , -1.0536038 ,  0.02091897, -0.8702738 ,
        0.95009375, -0.9187259 , -1.8877221 ,  0.59374857,  0.6501635 ,
       -0.3254898 , -1.3754797 , -1.2943144 ,  1.3063593 ,  1.6203603 ,
        1.9170743 ,  2.1614845 , -0.9923637 ,  0.616638  , -1.8561238 ,
       -0.897864  ,  0.63119555, -0.3960814 ,  0.23239917, -1.5750691 ,
        0.16524327,  1.8257805 , -0.02598399, -1.0150673 ,  0.64206785,
       -0.62078387, -0.08855089, -0.1757602 ,  1.0424634 ,  0.78948444],
      dtype=float32), 2]

I want to shuffle the original list so that the order of these nested elements changes. This is what I have written:

import random
shuffled_data = random.shuffle(data)

However, when I print "shuffled_data", it returns "None". How can I solve this problem?




Aucun commentaire:

Enregistrer un commentaire