Performant Python

Solutions

In [5]:
np.save("save_numpy.npy", data_set)
In [6]:
!cat save_numpy.npy
�NUMPYv{'descr': '<f8', 'fortran_order': False, 'shape': (50, 5), }                                                         
X����?��q���ɿFzP��?�;j��f�?���X�?"�^p���?L��Yؿ�)�S)�?V?<{L�?o�����?aH���?����6���c���?}̩���?���X�?*e#����?�<�G�㿪����?63@V�m�?����S�?�v'����?t��cuh�A�����?��V�e�?�1�����?[  zrdw���$_V�ą���?�ҟ�(&�?�T۶m��?s���ĿM��h~�O�_`J��?���݆��?�w��X�?  ��=5п�f�F��ؿL{��u�?��CpS���nJ�Cc�?|YQ�A1Կ����̿E���?^]�~Éп�����S@J���ֿSPe�,��X�]{H!�?g��ؿ-H���@٣2Y�տ�:�;J�?�v���?�zŪ�R߿�1����@gZ���ӿ2� �Y��?���sz;��r��Vu���)x9@�p�>�Ͽ��Ny�?~�Fm4�ȿ���j�῕T۶m�@���4�8ǿ3N"�s�?�5�jӿ#���n߿>�Cc}@#��DT2���8����?��r���ؿ�oo��Pؿ����X
@J���!h����`�>�?��_�ܿb*���̿�`
@2��LG�?ؿ�?���?���N>�ݿ��ȵ��?��)x9@cրt�Q�?�Ӣv%W��@�]hbڿ5���]�?�����S@��y��۝?����Ǻ�J5    ��Կr���D�?p$I�$@=���O?G6W:ſ�'<��ʿ*$¿]��?(t���@�c��;[��|�y�ȿ�v7�:���9�p��?�<4և�@���⠲�bɅ�&Uſ�QX�VB�?6���T�?�����@ �b߹���pH@���S�  ����?�*=�?\�Cc}h@K%ꯎ�OR���!���~�,�d�?"����*�?��)x9@O�o�!r����z(�O�?Dc�ן��?=��?؋S�r
�?7���b��?}]��VͿ�Cc}@��JI�b�?Z�#.�?�<U���?aHI׿��r
^N@0��p���?�灚���?aZ�c���?ڷ���bܿ����X@���J{�?e;�s�l�?��Ut�?c`�B޿?���S�@�b��R�?��Iǁ�?sf�\|�?�5g:@�ܿ�`
����Bu-���W��zѿs�Cc@��%�b��?9U6�9_ҿ��`E����:�.4ÿ1硱>4@�.M��?��oH��ܿ�����W¿/
������)x9@.
z�ʲr.�Y��������?���� @n��}�ʿ���%p�����O���"�[��?m�$I�$!@�kr��Կf��۔��gj��:Z��'3��?�yh��!@�;ɦ�ڿj�B(�)׿V ���?p�+���?+^���!@g�X�?޿(4�&Tƿp�Jl�?�Fc��줿�X�r
^"@5~���8߿Ŭ��]�?��6w!�b?O��Nѓ¿�<4և�"@혏\��ݿ��᳕��?��?+�m�sAοE!x9/#@Թ�i!�ٿ7w��v�?{V��H���&z餺$ӿ�����#@��Jze�ӿ�.��?I���Ŀ����Կ$@��}ȃɿ3Y�K2�?��^�/̿݁���ҿ

Clearly this is nonsense and something has gone wrong?

Or has it, lets try loading the file into a new array:

In [7]:
new_data_set = np.load("save_numpy.npy")
print(new_data_set)
[[ 0.00000000e+00  5.00000000e-01  0.00000000e+00  0.00000000e+00
   0.00000000e+00]
 [ 2.04081633e-01  4.79355330e-01 -2.00560658e-01  1.02684298e-02
   9.92266839e-02]
 [ 4.08163265e-01  4.19547901e-01 -3.80483604e-01  3.93778045e-02
   1.82021527e-01]
 [ 6.12244898e-01  3.26712157e-01 -5.21510425e-01  8.24678014e-02
   2.34157403e-01]
 [ 8.16326531e-01  2.10284231e-01 -6.09853878e-01  1.32166983e-01
   2.45536487e-01]
 [ 1.02040816e+00  8.19199477e-02 -6.37751288e-01  1.79589100e-01
   2.11590508e-01]
 [ 1.22448980e+00 -4.58327665e-02 -6.04293415e-01  2.15545729e-01
   1.33977027e-01]
 [ 1.42857143e+00 -1.60947443e-01 -5.15430837e-01  2.31820390e-01
   2.04793046e-02]
 [ 1.63265306e+00 -2.53249583e-01 -3.83163518e-01  2.22340934e-01
  -1.15880217e-01]
 [ 1.83673469e+00 -3.15506351e-01 -2.24014723e-01  1.84098970e-01
  -2.58408426e-01]
 [ 2.04081633e+00 -3.44147416e-01 -5.69808899e-02  1.17695360e-01
  -3.88798720e-01]
 [ 2.24489796e+00 -3.39535081e-01  9.87889495e-02  2.74372341e-02
  -4.89422957e-01]
 [ 2.44897959e+00 -3.05757463e-01  2.26298531e-01 -7.90325673e-02
  -5.45573689e-01]
 [ 2.65306122e+00 -2.49976952e-01  3.12712027e-01 -1.91534570e-01
  -5.47376832e-01]
 [ 2.85714286e+00 -1.81420709e-01  3.50819381e-01 -2.98487387e-01
  -4.91134081e-01]
 [ 3.06122449e+00 -1.10142962e-01  3.39783849e-01 -3.88243141e-01
  -3.79924687e-01]
 [ 3.26530612e+00 -4.57163349e-02  2.85084507e-01 -4.50462282e-01
  -2.23385440e-01]
 [ 3.46938776e+00  3.98333319e-03  1.97668007e-01 -4.77360592e-01
  -3.66898525e-02]
 [ 3.67346939e+00  3.37471033e-02  9.24213677e-02 -4.64675500e-01
   1.61154483e-01]
 [ 3.87755102e+00  4.16381495e-02 -1.38380935e-02 -4.12232019e-01
   3.49486985e-01]
 [ 4.08163265e+00  2.91588879e-02 -1.04600108e-01 -3.24036748e-01
   5.08390948e-01]
 [ 4.28571429e+00  9.62336093e-04 -1.65842916e-01 -2.07885293e-01
   6.21016383e-01]
 [ 4.48979592e+00 -3.58523032e-02 -1.87883195e-01 -7.45274225e-02
   6.75547333e-01]
 [ 4.69387755e+00 -7.27674263e-02 -1.66661110e-01  6.35122381e-02
   6.66575439e-01]
 [ 4.89795918e+00 -1.01064832e-01 -1.04297655e-01  1.93318318e-01
   5.95713253e-01]
 [ 5.10204082e+00 -1.13076132e-01 -8.85328341e-03  3.03009313e-01
   4.71373965e-01]
 [ 5.30612245e+00 -1.03304007e-01  1.06683264e-01  3.83033715e-01
   3.07745598e-01]
 [ 5.51020408e+00 -6.92685087e-02  2.26050250e-01  4.27184569e-01
   1.23085937e-01]
 [ 5.71428571e+00 -1.19668422e-02  3.31805786e-01  4.33213962e-01
  -6.24531545e-02]
 [ 5.91836735e+00  6.41166345e-02  4.07596022e-01  4.02977704e-01
  -2.29206411e-01]
 [ 6.12244898e+00  1.51457225e-01  4.40313134e-01  3.42097600e-01
  -3.60290595e-01]
 [ 6.32653061e+00  2.40341835e-01  4.21871329e-01  2.59188507e-01
  -4.43537193e-01]
 [ 6.53061224e+00  3.20025152e-01  3.50374330e-01  1.64747722e-01
  -4.72829355e-01]
 [ 6.73469388e+00  3.80048038e-01  2.30523049e-01  6.98468902e-02
  -4.48684747e-01]
 [ 6.93877551e+00  4.11555932e-01  7.32064015e-02 -1.52118193e-02
  -3.78019978e-01]
 [ 7.14285714e+00  4.08453306e-01 -1.05682160e-01 -8.21102535e-02
  -2.73132021e-01]
 [ 7.34693878e+00  3.68248616e-01 -2.87062139e-01 -1.25451478e-01
  -1.50029980e-01]
 [ 7.55102041e+00  2.92481733e-01 -4.50899192e-01 -1.43307793e-01
  -2.63293771e-02]
 [ 7.75510204e+00  1.86675936e-01 -5.78583123e-01 -1.37316655e-01
   8.10254552e-02]
 [ 7.95918367e+00  5.98145869e-02 -6.55160439e-01 -1.12318619e-01
   1.57924782e-01]
 [ 8.16326531e+00 -7.65995131e-02 -6.71148935e-01 -7.55886544e-02
   1.94873035e-01]
 [ 8.36734694e+00 -2.09792836e-01 -6.23710702e-01 -3.57629041e-02
   1.88162370e-01]
 [ 8.57142857e+00 -3.27130663e-01 -5.17038755e-01 -1.60086853e-03
   1.40295405e-01]
 [ 8.77551020e+00 -4.17520234e-01 -3.61907996e-01  1.92568993e-02
   5.96063457e-02]
 [ 8.97959184e+00 -4.72640597e-01 -1.74443113e-01  2.13753624e-02
  -4.08698213e-02]
 [ 9.18367347e+00 -4.87852974e-01  2.57483724e-02  2.31558357e-03
  -1.45136036e-01]
 [ 9.38775510e+00 -4.62684002e-01  2.17852319e-01 -3.69733348e-02
  -2.36359531e-01]
 [ 9.59183673e+00 -4.00825837e-01  3.82258145e-01 -9.22131894e-02
  -2.99116765e-01]
 [ 9.79591837e+00 -3.09655542e-01  5.02811737e-01 -1.56301609e-01
  -3.21472546e-01]
 [ 1.00000000e+01 -1.99334203e-01  5.68639629e-01 -2.20201536e-01
  -2.96629104e-01]]

save and load use a special binary representation to preserve (in principle) the numpy obejcts. This mean that you shouldn't see variation due to reading and writing with precision error, or between different implementations of numpy, different computers etc.