Let's say I have a numpy array a = numpy.array([1,2,3,4]). Now
str(a) will give me "[1 2 3 4]". How do I convert the string "[1 2 3 4]" back to a numpy.array([1,2,3,4])?
-
I would ask why you want to do that instead of just keeping the array, but you can "split" on the spaces. arr = numpy.array(s.split(' '))Christian Sloper– Christian Sloper2019-11-22 11:25:01 +00:00Commented Nov 22, 2019 at 11:25
-
@ChristianSloper I am writing these numpy arrays to csv files (gets written as shown in example) and i want to be able to read them back as numpy arrayscyber_tooth– cyber_tooth2019-11-22 11:27:57 +00:00Commented Nov 22, 2019 at 11:27
-
Use savetext() from numpy to store them properlyChristian Sloper– Christian Sloper2019-11-22 11:29:14 +00:00Commented Nov 22, 2019 at 11:29
Add a comment
|