I take an image from webcam in python, it is an array so I convert it to string using numpy.array_str(), now after doing that I need to convert that string back to an array as efficiently as possible.
I have already tried it using for statements but it takes around half a second, which is just too slow for my use-case. I have even searched the web for numpy's built-in function to do the task but did not find any solution.
1 Answer
The numpy.array_str() function returns a string with a whitespace separator between the array elements as https://numpy.org/doc/stable/reference/generated/numpy.array_str.html
To convert it back to an array, you can use str.split() without specifying the delimiter because it considers whitespace as default.
numpy.save(binary) ornumpy.savetxt(human readable) instead