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])
?
Asked
Active
Viewed 93 times
1

cyber_tooth
- 133
- 2
- 9
-
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 Nov 22 '19 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 arrays – cyber_tooth Nov 22 '19 at 11:27
-
Use savetext() from numpy to store them properly – Christian Sloper Nov 22 '19 at 11:29