Convert str(array) back to numpy array

If we print a numpy array, which actually use str(), we will find it almost irreversible.

InĀ [5]:
l=arange(16).reshape(4,4)
print('l is printed as:\n', l)
l is printed as:
 [[ 0  1  2  3]
 [ 4  5  6  7]
 [ 8  9 10 11]
 [12 13 14 15]]

Use print() will fallback to str(), so str() is not the correct way.

  • repr()
  • .tolist()
more ...