0

I want the Face Encodings which are stored in the dictionary to be stored in the Database in simple text. So, The dict looks like this...

Simple Data in Numpy Array


array([[-0.24684101,  1.0770087 , -0.46549857,  0.6899651 , -0.0172088 ,
         0.01917161,  2.4694798 , -2.6767805 , -0.50126964,  0.8047828 ,
        -0.21555606, -1.5408617 , -2.5809233 , -2.22431   , -1.2130492 ,
         1.08409   ,  1.2381219 ,  1.3944834 , -0.44548434,  0.12717676,
         1.611825  ,  0.25434235,  0.97729284, -1.131029  , -0.01471538,
         0.09575878,  0.10347354, -0.919141  , -0.20919399,  1.0275906 ,
        -0.72333205,  0.49255764, -1.2665565 ,  0.03819553,  2.3665667 ,
        -1.690517  , -0.293503  ,  0.89463717,  2.0341184 , -0.5328591 ,
        -1.1375701 , -0.39930856, -1.1450138 ,  2.0410218 ,  1.8398683 ,
        -0.97768176, -0.64299   ,  0.28698102, -0.52683306,  2.1747525 ,
        -1.0573564 , -0.6905593 , -0.4804876 ,  0.32964003,  0.3177481 ,
         1.2425584 ,  0.7790326 ,  0.27686158, -1.7098534 , -0.99255556,
        -0.7112258 , -1.7642928 ,  0.5029412 , -1.4172037 , -1.5987507 ,
         2.1605237 , -0.6220295 ,  0.5533376 ,  0.6955076 , -1.2478447 ,
        -1.5054828 , -0.12723197, -0.50764024, -1.234578  , -0.04605554,
        -0.6447917 , -1.6816235 , -1.0286163 , -0.47162792, -0.20693539,
         0.0860045 ,  0.5372213 ,  0.29363748,  0.91555727,  0.52423084,
         1.4659382 ,  0.6950233 , -0.65398884, -0.91441524,  0.95101625,
        -0.33743462,  0.2010487 ,  0.4070103 ,  0.8570372 , -0.414096  ,
        -1.2613487 , -0.12721302, -1.9749248 , -1.0874395 , -0.45438108,
        -1.0385392 ,  1.0453774 , -0.5049066 ,  0.16661291,  0.10959264,
        -2.547219  , -0.49483693,  0.7551471 , -0.7333046 , -0.45841357,
         1.0003595 , -0.7349028 ,  1.5753592 ,  1.7150695 , -2.0518181 ,
         0.218887  ,  0.3429606 ,  0.80745304, -0.9821863 ,  0.59469235,
         1.0098441 ,  1.4132774 ,  0.69519347, -1.5112026 , -2.7171316 ,
         0.5496241 , -1.0044149 , -1.2788291 ],
       [-0.6814048 , -1.678967  , -0.6895096 ,  0.73741305,  0.8187343 ,
        -0.25810438, -0.02746152, -1.5952878 , -1.3193005 ,  2.304433  ,
        -0.83021337, -0.694108  ,  0.40333563, -1.7780415 ,  0.8667511 ,
         1.5608184 ,  2.8885214 ,  0.27455485,  0.39580122, -0.70851016,
         1.6965772 , -0.47489813,  0.02705503,  0.9047853 , -1.1335149 ,
         0.54731226,  0.35241312,  0.3444583 ,  0.9659247 ,  2.796852  ,
         1.216329  , -0.19315745, -1.141908  ,  0.55104446,  1.0655097 ,
         0.22545013, -1.3412933 , -0.06974155,  1.7984283 , -0.9083147 ,
        -0.36632693,  0.53321826,  0.621454  ,  0.19186446,  2.0352554 ,
         0.49825913,  0.6615877 , -0.38520163, -0.02794069,  0.9559599 ,
        -0.8086782 , -0.24737592, -1.329782  ,  0.5108012 ,  0.03378259,
        -0.17455904, -0.33631605, -1.495397  ,  0.5728296 , -1.0695695 ,
        -1.8948505 , -1.1576259 ,  1.7695637 , -0.8986906 , -1.2671214 ,
         1.0098033 , -0.28550452, -0.18761517, -1.0739486 ,  0.63779855,
         0.6448764 ,  0.3904781 ,  1.2511398 , -0.95680857,  1.1699883 ,
         0.20616718, -1.0123537 , -0.26720193, -0.8307072 ,  0.45199633,
        -1.9060786 ,  0.3433256 , -0.9012116 ,  0.20430557,  0.7669535 ,
         1.5549779 , -0.9333616 ,  0.0558961 , -1.2128843 ,  0.6361645 ,
         1.9935343 ,  2.8673058 , -0.0337045 ,  1.8604296 ,  0.45951045,
        -0.58515525,  0.7033641 ,  0.34443223, -1.9315164 , -0.3470185 ,
         0.6353385 ,  0.52725655,  0.7469518 , -0.8218752 , -0.12755996,
        -0.31389737, -1.3008058 ,  0.9091612 , -0.8560178 ,  0.77165955,
        -0.05318193,  0.19349894,  0.19148578,  0.07630757,  0.6013402 ,
        -1.2795165 ,  0.48696873, -0.11383422, -1.186056  , -1.0967742 ,
         1.1388265 ,  0.2482484 ,  2.1056433 , -1.8991177 , -1.4477395 ,
        -1.4994648 ,  0.46171623, -1.669493  ]], dtype=float32)

A Simple Numpy Array of shape (2,128)

Now, I want to store "it" as the plain text in the Database (MySQL) So I converted it into string...

String = str(npArray)

And that came back :

'[[-0.24684101  1.0770087  -0.46549857  0.6899651  -0.0172088   0.01917161\n   2.4694798  -2.6767805  -0.50126964  0.8047828  -0.21555606 -1.5408617\n  -2.5809233  -2.22431    -1.2130492   1.08409     1.2381219   1.3944834\n  -0.44548434  0.12717676  1.611825    0.25434235  0.97729284 -1.131029\n  -0.01471538  0.09575878  0.10347354 -0.919141   -0.20919399  1.0275906\n  -0.72333205  0.49255764 -1.2665565   0.03819553  2.3665667  -1.690517\n  -0.293503    0.89463717  2.0341184  -0.5328591  -1.1375701  -0.39930856\n  -1.1450138   2.0410218   1.8398683  -0.97768176 -0.64299     0.28698102\n  -0.52683306  2.1747525  -1.0573564  -0.6905593  -0.4804876   0.32964003\n   0.3177481   1.2425584   0.7790326   0.27686158 -1.7098534  -0.99255556\n  -0.7112258  -1.7642928   0.5029412  -1.4172037  -1.5987507   2.1605237\n  -0.6220295   0.5533376   0.6955076  -1.2478447  -1.5054828  -0.12723197\n  -0.50764024 -1.234578   -0.04605554 -0.6447917  -1.6816235  -1.0286163\n  -0.47162792 -0.20693539  0.0860045   0.5372213   0.29363748  0.91555727\n   0.52423084  1.4659382   0.6950233  -0.65398884 -0.91441524  0.95101625\n  -0.33743462  0.2010487   0.4070103   0.8570372  -0.414096   -1.2613487\n  -0.12721302 -1.9749248  -1.0874395  -0.45438108 -1.0385392   1.0453774\n  -0.5049066   0.16661291  0.10959264 -2.547219   -0.49483693  0.7551471\n  -0.7333046  -0.45841357  1.0003595  -0.7349028   1.5753592   1.7150695\n  -2.0518181   0.218887    0.3429606   0.80745304 -0.9821863   0.59469235\n   1.0098441   1.4132774   0.69519347 -1.5112026  -2.7171316   0.5496241\n  -1.0044149  -1.2788291 ]\n [-0.6814048  -1.678967   -0.6895096   0.73741305  0.8187343  -0.25810438\n  -0.02746152 -1.5952878  -1.3193005   2.304433   -0.83021337 -0.694108\n   0.40333563 -1.7780415   0.8667511   1.5608184   2.8885214   0.27455485\n   0.39580122 -0.70851016  1.6965772  -0.47489813  0.02705503  0.9047853\n  -1.1335149   0.54731226  0.35241312  0.3444583   0.9659247   2.796852\n   1.216329   -0.19315745 -1.141908    0.55104446  1.0655097   0.22545013\n  -1.3412933  -0.06974155  1.7984283  -0.9083147  -0.36632693  0.53321826\n   0.621454    0.19186446  2.0352554   0.49825913  0.6615877  -0.38520163\n  -0.02794069  0.9559599  -0.8086782  -0.24737592 -1.329782    0.5108012\n   0.03378259 -0.17455904 -0.33631605 -1.495397    0.5728296  -1.0695695\n  -1.8948505  -1.1576259   1.7695637  -0.8986906  -1.2671214   1.0098033\n  -0.28550452 -0.18761517 -1.0739486   0.63779855  0.6448764   0.3904781\n   1.2511398  -0.95680857  1.1699883   0.20616718 -1.0123537  -0.26720193\n  -0.8307072   0.45199633 -1.9060786   0.3433256  -0.9012116   0.20430557\n   0.7669535   1.5549779  -0.9333616   0.0558961  -1.2128843   0.6361645\n   1.9935343   2.8673058  -0.0337045   1.8604296   0.45951045 -0.58515525\n   0.7033641   0.34443223 -1.9315164  -0.3470185   0.6353385   0.52725655\n   0.7469518  -0.8218752  -0.12755996 -0.31389737 -1.3008058   0.9091612\n  -0.8560178   0.77165955 -0.05318193  0.19349894  0.19148578  0.07630757\n   0.6013402  -1.2795165   0.48696873 -0.11383422 -1.186056   -1.0967742\n   1.1388265   0.2482484   2.1056433  -1.8991177  -1.4477395  -1.4994648\n   0.46171623 -1.669493  ]]'

A whole String of Np Array with \n in between.

On this stage, I can store it inside the Database.

But how to convert it back into Numpy Array from the String ?

Please Help.

KAKAKAKI
  • 93
  • 7
  • use pythons pickle. – Florian H Jan 07 '20 at 12:28
  • Similar problem with a pandas csv - https://stackoverflow.com/q/59619773/901925 – hpaulj Jan 07 '20 at 16:19
  • Does it have to be readable text? SImple `csv` format is best for storing 2d arrays, just the numbers in neat rows and columns without brackets and such. Anything else is harder to parse. But if it doesn't have to human-readable, you can make a bytestring that has shape information and is easier to process. – hpaulj Jan 07 '20 at 17:47
  • Thanks for giving your interest in my question @hpaulj. I am actually trying to store the Numpy array which is full of float32 numbers, which has to b converted into the string and then stored in the database as a single data in a row. – KAKAKAKI Jan 13 '20 at 16:24

0 Answers0